PHP - WooCommerce - get_order()

Moobs

Regular Member
Joined
Jan 30, 2015
Messages
276
Reaction score
24
I'm trying to create a function that will retrieve an order by its ID. For some reason I can't get the WC 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.

Code:
function getWC_order_details($id){     global $woocommerce;

    $order = get_order( $id );

    print "<pre>";
    print_r($order);
    print "</pre>"; }

Test Output:

Code:
<php getWC_order_details(466); ?>

Note: I have tested echoing other data out of the function without a problem.

Any help would be greatly appreciated.
 
Have you tried (in functions.php):

Code:
function getWC_order_details($id){
	global $woocommerce;
	
	$order = new WC_Order( $id );


	print "<pre>";
	print_r($order);
	print "</pre>";
}
 
Back
Top