wc_get_order on function.php gerenate error
-
i’m using “woocommerce_payment_complete” to insert some product data in a DB.
i need to get the id of the product that the client bought.
i already search a lot of thing and everyone said to use this."$order = wc_get_order(11975); $items = $order->get_items();"It work on template files like ‘thankyou’ etc.
but i need to use this in function.php and i get this error.“Call to a member function get_order() on a non-object”
i can’t figure out what i need to call inside the “woocommerce_payment_complete” action to solve this.
Any hints?
If i try use this
$order = new WC_Order(11266); $items = $order->get_items(); foreach ( $items as $item ) { // echo $item['product_id'] . "<br>"; var_dump($item['product_id']); }the result is NULL
wp 4.3.1
woo 2.4.10
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘wc_get_order on function.php gerenate error’ is closed to new replies.