1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP - WooCommerce - get_order()

Discussion in 'PHP & Perl' started by Moobs, Mar 4, 2015.

  1. Moobs

    Moobs Regular Member

    Joined:
    Jan 30, 2015
    Messages:
    238
    Likes Received:
    14
    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.
     
  2. Darkhodge

    Darkhodge Newbie

    Joined:
    Feb 27, 2015
    Messages:
    15
    Likes Received:
    3
    Occupation:
    Web Developer
    Location:
    Surrey, UK
    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>";
    }
    
     
    • Thanks Thanks x 1