久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 WooCommerce 3 中獲取訂單運送物品的詳細信息

Get orders shipping items details in WooCommerce 3(在 WooCommerce 3 中獲取訂單運送物品的詳細信息)
本文介紹了在 WooCommerce 3 中獲取訂單運送物品的詳細信息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何獲取訂單配送方式 ID.?

例如'flat_rate'.

For example 'flate_rate'.

自從 WooCommerce 3 以來,一切都發生了變化,現在變得很復雜.

Since WooCommerce 3 it is now complicated as everything has changed.

我已經在 foreach 循環中使用 $order->get_data() 進行了嘗試,但數據受到保護.

I have tried it with $order->get_data() in a foreach loop but the data is protected.

推薦答案

如果您想獲取 Order Items Shipping 數據,您需要先在 foreach 循環中獲取它們(對于 'shipping' 項目類型)并使用 WC_Order_Item_Shipping 方法訪問數據

If you want to get the Order Items Shipping data, you need first to get them in a foreach loop (for 'shipping' item type) and to use WC_Order_Item_Shipping methods to access data

$order_id = 528; // For example

// An instance of 
$order = wc_get_order($order_id);

// Iterating through order shipping items
foreach( $order->get_items( 'shipping' ) as $item_id => $item ){
    $order_item_name             = $item->get_name();
    $order_item_type             = $item->get_type();
    $shipping_method_title       = $item->get_method_title();
    $shipping_method_id          = $item->get_method_id(); // The method ID
    $shipping_method_instance_id = $item->get_instance_id(); // The instance ID
    $shipping_method_total       = $item->get_total();
    $shipping_method_total_tax   = $item->get_total_tax();
    $shipping_method_taxes       = $item->get_taxes();
}

您還可以使用 WC_Data 方法 get_data() 在這個 foreach 循環中:

You can also get an array of this (unprotected and accessible) data using the WC_Data method get_data() inside this foreach loop:

$order_id = 528; // For example

// An instance of 
$order = wc_get_order($order_id);

// Iterating through order shipping items
foreach( $order->get_items( 'shipping' ) as $item_id => $item ){
    // Get the data in an unprotected array
    $item_data = $item->get_data();

    $shipping_data_id           = $item_data['id'];
    $shipping_data_order_id     = $item_data['order_id'];
    $shipping_data_name         = $item_data['name'];
    $shipping_data_method_title = $item_data['method_title'];
    $shipping_data_method_id    = $item_data['method_id'];
    $shipping_data_instance_id  = $item_data['instance_id'];
    $shipping_data_total        = $item_data['total'];
    $shipping_data_total_tax    = $item_data['total_tax'];
    $shipping_data_taxes        = $item_data['taxes'];
}

要完成,您可以使用以下 WC_Abstract_Order 與運輸數據"相關的方法,例如以下示例:

To finish you can use the following WC_Abstract_Order methods related to "Shipping data", like in this examples:

// Get an instance of the WC_Order object
$order = wc_get_order(522);

// Return an array of shipping costs within this order.
$order->get_shipping_methods(); // same thing than $order->get_items('shipping')

// Conditional function based on the Order shipping method 
if( $order->has_shipping_method('flat_rate') ) { 

    // Output formatted shipping method title.
    echo '<p>Shipping method name: '. $order->get_shipping_method()) .'</p>';

這篇關于在 WooCommerce 3 中獲取訂單運送物品的詳細信息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 国产精品久久久久久久久免费 | 日本亚洲一区二区 | 午夜激情影院 | 日韩精品免费在线观看 | 亚洲国产精品99久久久久久久久 | 日日综合 | 成人欧美一区二区三区在线播放 | 久久99久久| www..com18午夜观看 | 国产午夜精品视频 | 成人一区在线观看 | 中国av在线免费观看 | 亚洲成人av一区二区 | 天天综合成人网 | 又爽又黄axxx片免费观看 | 精品国产成人 | 免费国产成人av | 久久久久久国产 | 天天操夜夜拍 | 91精品一区 | 亚洲精品电影网在线观看 | 91视频一区二区三区 | 成年人免费在线视频 | 99国产精品视频免费观看一公开 | 欧美日韩视频在线 | 久草在线 | 久久99精品视频 | 91久久夜色精品国产网站 | 久久精品国产精品青草 | 久久久久国产精品 | 成人在线视频网站 | 免费同性女女aaa免费网站 | 久久精品99久久 | 日韩一级免费电影 | 久久爆操 | 亚洲91| 97色伦网| 日本不卡一区二区三区在线观看 | 日韩欧美一级精品久久 | 日韩精品一区二区三区中文在线 | 欧美久久久久久 |