user568021 user568021 - 1 year ago 652
PHP Question

woocommerce_order_status_completed not triggered

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

Like here:


And here:

But I cannot help myself with answers that these guys received.

I tried to add the action a few different 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 a 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 put the action outside of the class:

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

None of these examples work. :(

Answer Source

Following steps to check before you own hook called.

  1. Check when you complete order got any email about order completion email provide by default woocommerce emails in your admin dashboard woocommerce settings.

  2. Hook is registered properly in plugin file or theme functions.php

Check your register action woocommerce_order_status_completed after is registered properly Following this way

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 in 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 in array callback function then it's working when not something issue in other plugins or theme functions.php file. Find string in whole plugin or theme function.php have remove_action or remove_all_actions is called.

You can also check in this way

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

Change function priority 10 to 1 mean your function is call soon any others callback functions with registered with this hook.

Sorry for poor English.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download