I’m trying to create a function that will retrieve an order by its ID. For some reason I can’t get the WooCommerce global function get_order
to work. I’m passing a valid order id
to the function and trying to print it out to verify that it’s working. The function has been placed in my functions.php
file.
function getWC_order_details($id){
global $woocommerce;
$order = get_order( $id );
print "<pre>";
print_r($order);
print "</pre>";
}
I have tested echoing other data out of the function without a problem.
First of all make function like this :
After that, use it with some
woo_commerce
action or filter.So after adding any product to the cart, you will see after cart table that there is one array containing all the details.
NOTE : You can use any other action or filter and you can find them here.
EDITED:
Try this. It might be useful to you.
Source:
File name: woocommerce/includes/api/class-wc-api-orders.php