Woocommerce_order_status_completed not starting

I want to write a custom plugin that takes some action after completing a woocommerce order, but I can't get this hook to work. I see this question many times.

Like here: https://wordpress.stackexchange.com/questions/134463/woocommerce-order-status-completed-action-hook-not-working

Here: https://wordpress.org/support/topic/woocommerce_order_status_completed-is-not-working

And here: https://wordpress.org/support/topic/woocommerce_order_status_completed-action-hook-not-working

But I can not help myself in the answers that these guys received.

I tried to add an action in several ways:

add_action( 'woocommerce_order_status_completed', 'ikwoocommerceorderstatuscompleted_func'); add_action( 'woocommerce_order_status_completed', array($this,'ikwoocommerceorderstatuscompleted_func'), 10, 1); add_action( 'woocommerce_order_status_completed', array(&$this,'ikwoocommerceorderstatuscompleted_func'), 10, 1); 

Also tried with class:

 class IKHooks { function __construct() { add_action( 'woocommerce_order_status_completed', array($this,'ikwoocommerceorderstatuscompleted_func'), 10, 1); } public function ikwoocommerceorderstatuscompleted_func( $order_id ) { } } 

I even tried to push the action outside the class:

 add_action( 'woocommerce_order_status_completed', array(IKHooks,'ikwoocommerceorderstatuscompleted_func'), 10, 1); 

None of these examples work. :(

+6
source share
6 answers

The following steps are for verification before calling the called user.

  • Check when you complete the order, whether you received an e-mail about the completion of the order, by e-mail specify the default woocommerce emails in the woocommerce settings of your administrator account.

  • The hook is registered correctly in the plugin file or in the theme.php function

Check the validity of your register woocommerce_order_status_completed after registration Following this path

 add_action( 'woocommerce_order_status_completed', 'callback_function_name' ); global $wp_filter; // test is register action name with callback function print_r($wp_filter); exit; 

check array, your function name is registered with this hook

 [woocommerce_order_status_completed] => Array ( [10] => Array ( [wc_paying_customer] => Array ( [function] => wc_paying_customer [accepted_args] => 1 ) [wc_downloadable_product_permissions] => Array ( [function] => wc_downloadable_product_permissions [accepted_args] => 1 ) [callback_function_name] => Array ( [function] => callback_function_name [accepted_args] => 3 ) ) ) 

When you find a callback function in an array, it works when something doesn't happen in other plugins or theme functions.php file. To find the string as a whole of the plugin or theme function.php is called remove_action or remove_all_actions.

You can also check this method.

 add_action( 'woocommerce_order_status_completed', 'callback_function_name', 1); 

Changing the priority of a function from 10 to 1 means that your function will soon call any other callback functions with this hook registered.

Sorry for the bad english.

+6
source

This hook can be used

 add_action( 'woocommerce_order_status_changed', 'your_function', 99, 3 ); 

And the function will look like

 function your_function( $order_id, $old_status, $new_status ){ if( $new_status == "completed" ) { //your code here } } 

Hope this will be helpful.

+3
source

Try using the action hook woocommerce_order_status_changed . It takes 3 parameters. order ID, old status and new status. Further link to the code HERE

This may not be entirely suitable for your requirement, but it seems to be worth the alternative. Hope this helps.

+1
source

I ran into a similar problem earlier and solved it as:

After updating the code, the order status is completed

 add_action( 'woocommerce_thankyou', 'your_wc_autocomplete_order' ); function your_wc_autocomplete_order( $order_id ) { if ( ! $order_id ) { return; } $order = wc_get_order( $order_id ); $order->update_status( 'completed' ); } 

Once the order is completed, if you want to do something, see the following code:

 add_action('woocommerce_order_status_completed','payment_complete'); function payment_complete($order_id) { //global $items; //$order = new WC_Order($order_id); // do something ... } 

Hope it will work :)

+1
source

woocommerce_order_status_changed and woocommerce_order_status_completed really work for me. After the battles for 2 days, I realized that you just can’t var_dump or var_export or print_r or anything else in the admin panel, it just won’t work.

So, if you are a beginner like me, and thought that these actions do not work, just try to start another action, for example, send mail, for example.

This code works:

 function your_function( $order_id ){ $order = new WC_Order( $order_id ); $to_email = ' testing_mail@sample.com '; $payment = $order->get_payment_method_title(); $headers = 'From: Your Name < Your_site_mail@address.com >' . "\r\n"; wp_mail($to_email, 'subject', $payment, $headers ); } add_action( 'woocommerce_order_status_completed', 'your_function'); 
+1
source

I think you can be after this guy. woocommerce_payment_complete

 function mysite_woocommerce_payment_complete( $order_id ) { error_log( "Payment has been received for order $order_id", 0 ); } add_action( 'woocommerce_payment_complete', 'mysite_woocommerce_payment_complete' ); 
0
source

All Articles