woocommerce_order_status_completed hook does not run
-
Hi There!
I am using woocommerce_order_status_completed hook so that I can add the advertiser role for each customer who is buying a subscription. Actually, I have 4 subscription products and I want customers to be both subscribers + advertisers if they will buy these products. For other products, I want them to be only subscribers.
I have tried my code in different ways but still, I am unable to execute this specific hook. If the same hook or anything else can solve my problem, I will appreciate your help. I have also tried woocommerce_order_status_changed and woocommerce_order_status_processing but still, nothing is executing inside these hooks.
Until now, I have used this code.
add_action( 'woocommerce_order_status_completed', 'so_29647785_convert_customer_role' ); function so_29647785_convert_customer_role( $order_id ) { $order = new WC_Order( $order_id ); if ( $order->user_id > 0 ) { foreach ( $order->get_items() as $order_item ) { if( 4008 == $order_item[ 'product_id' ] ) { $user = new WP_User( $order->user_id ); $user->remove_role( 'Subscriber' ); // Add new role $user->add_role( 'Advertiser' ); } } } }
- The topic ‘woocommerce_order_status_completed hook does not run’ is closed to new replies.