Detect WooCommerce order status changed

I’m developing a simple WordPress plugin that adds some credits to a table when the admin marks a order as “completed”.
My plugin.php looks like this:

<?php 
   function add_credits($order_status, $order_id) {
        global $wpdb, $woocommerce, $current_user;
        $order = new WC_Order($order_id);
        $items = $order->get_items();

         //DO SOME STUFF HERE with items and order
   }//function

   add_action('woocommerce_order_status_completed',   'add_credits');    

But, when I change the order to “COMPLETE”, this plugin does not make nothing. I can even write an echo or a simple instruction at the first line of the function, and doesn’t run.

Related posts

Leave a Reply

1 comment