WooCommerce - get_order() doesn't work and it returns zero WooCommerce - get_order() doesn't work and it returns zero wordpress wordpress

WooCommerce - get_order() doesn't work and it returns zero


You need to create an object for $order to use it with get_total(). Try this:

global $woocommerce;$order = new WC_Order($order_id);$total = $order->get_total(); //Get the total price of the order.$bonusPoints -= (int)$total; //calculate the new bonusPoints

Update1: This is just solving the internal data error. We need to get the $order_id to get it work…

Note: You can remove global $woocommerce;before $order = new WC_Order($order_id); because is already included in public function reducePoints( ){


Update2 - The good track:

Remove my code:

global $woocommerce;$order = new WC_Order($order_id); 

Then at line 89 of your code just add $order in:

public function reducePoints( $order ){    global $woocommerce;    // ...

Really happy that this works… It was a long search...