• I am developing woocommerce extension wher i need to perform some task after order is successfully completed. For that I started coding. I used following code in constructor of my class.

    add_action(‘woocommerce_order_status_completed’,array(&$this,’insert_points’),10,1);

    Then I defined function as follows:

    public function insert_points($order_id)
    {
       global $woocommerce, $table_prefix;
       $order = new WC_Order($order_id);
       var_dump($order);
    }

    But it is not working. Can anybody please help me using code sample.

Viewing 1 replies (of 1 total)
  • Hi,
    to do something after Woocommerce order completed INTO A CLASS, try this:

    <?php
    add_action( 'woocommerce_order_status_completed', array( $this,'my_function')  );
    /*
     * Do something after WooCommerce sets an order on completed
     */
    function my_function($order_id) {
    
    	// order object (optional but handy)
    	$order = new WC_Order( $order_id );
    
    	// do some stuff here
    
    }

    First you have to declare your public function __construct()

Viewing 1 replies (of 1 total)
  • The topic ‘woocommerce_order_status_completed action hook not working’ is closed to new replies.