Reputation: 4227
I registered few custom post statuses. And i wanna hook it when order received. i try it by:
add_action('woocommerce_checkout_order_processed', 'aa_func_20151609121636',30, 2);
function aa_func_20151609121636($order_id, $posted)
{
global $wpdb;
$post_status = null;
if(isset($_POST['yes_its_enq']) && ($_POST['yes_its_enq'] === 'yes')) {
$post_status = 'wc-gibraenquiry';
} else {
$post_status ='wc-gibrapending';
}
$wpdb->update( $wpdb->posts, array( 'post_status' => $post_status ), array( 'ID' => $order_id ) );
}
but i failled and post status is wc-processing What the right hook for it?
Upvotes: 2
Views: 351
Reputation: 14913
Use the update_status
method of WC_Order class to update the status.
Try the following code:
add_action('woocommerce_checkout_order_processed', 'aa_func_20151609121636',30, 2);
function aa_func_20151609121636($order_id, $posted)
{
$order = new WC_Order( $order_id );
if( isset( $posted['yes_its_enq'] ) && ( $posted['yes_its_enq'] === 'yes' ) ) {
$post_status = 'wc-gibraenquiry';
} else {
$post_status ='wc-gibrapending';
}
$order->update_status( $post_status );
}
Upvotes: 1