woocommerce_order_status_completed not triggered
Check the following steps before calling your hook.
Check if order completion email is sent.
Hook is properly registered in plugin file or theme
functions.php
add_action( 'woocommerce_order_status_completed','callback_function_name' );
function callback_function_name(){
global $wp_filter;
print_r($wp_filter);
exit;
}
Check if the name of your callback function is in the hook array:
[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
)
)
)
If you find it then everything is ok, it means that probably there's an issue with your theme or functions.php
file. Check for the hook or callback function in your files and then look for remove_action
or remove_all_actions
that's probably what's preventing your hook from being called.
You can also check in this way
add_action( 'woocommerce_order_status_completed', 'callback_function_name', 1);
Change the priority of your hook from 10 to 1 so it is called first than any other action or hook.
You can use this hook
add_action( 'woocommerce_order_status_changed', 'your_function', 99, 4 );
And the function will look like
function your_function( $order_id, $old_status, $new_status, $order ){
if( $new_status == "completed" ) {
//your code here
}
}
Hope this will be helpful.