WooCommerce - get_order() is not working

▼魔方 西西 提交于 2019-12-05 06:38:39

First of all make function like this :

function getWC_order_details($order_id) { 
    $order = new WC_Order( $order_id );
    var_dump($order);
}

After that, use it with some woo_commerce action or filter.

function use_after_cart_table(){
    getWC_order_details(40);
}
add_action( 'woocommerce_after_cart_table', 'use_after_cart_table' );

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:

function getWC_order_details($order_id) { 
    $order = new WC_Order( $order_id );
    //var_dump($order);
    $order_shipping_total = $order->get_shipping();
    $order_shipping_method = $order->get_shipping_methods();
    var_dump($order_shipping_total);//Use it for debugging purpose or to see details in that array
    var_dump($order_shipping_method);//Use it for debugging purpose or to see details in that array

    $_order =   $order->get_items(); //to get info about product
    foreach($_order as $order_product_detail){
        //var_dump($order_product_detail);
        echo "<b>Product ID:</b> ".$order_product_detail['product_id']."<br>";
        echo "<b>Product Name:</b> ".$order_product_detail['name']."<br><br>";
    }
    //var_dump($_order);
}
Shravan Sharma

try this.It might be useful to you.

function getWC_order_details($id)
{
 $array = WC_API_Orders::get_order( $id, $fields );
 print "<pre>";
 print_r($order);
 print "</pre>";
}

Source: File name: woocommerce/includes/api/class-wc-api-orders.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!