Php 获取WooCommerce 3中的订单发货项目详细信息
如何获取订单发货方法id 例如“固定利率” 自从WooCommerce 3以来,一切都变了,现在变得复杂了Php 获取WooCommerce 3中的订单发货项目详细信息,php,woocommerce,orders,shipping,shipping-method,Php,Woocommerce,Orders,Shipping,Shipping Method,如何获取订单发货方法id 例如“固定利率” 自从WooCommerce 3以来,一切都变了,现在变得复杂了 我已经在foreach循环中使用了$order->get_data(),但是数据是受保护的。如果您想获取订单项目发货数据,首先需要在foreach循环中获取它们(对于'Shipping'项目类型),并使用方法访问数据 $order_id = 528; // For example // An instance of $order = wc_get_order($order_id);
我已经在foreach循环中使用了
$order->get_data()
,但是数据是受保护的。如果您想获取订单项目发货数据,首先需要在foreach循环中获取它们(对于'Shipping'
项目类型),并使用方法访问数据
$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();
}
您还可以使用此foreach循环内的方法获取此(未受保护且可访问)数据的数组:
$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'];
}
要完成此操作,您可以使用以下与“装运数据”相关的方法,如以下示例所示:
// 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>';
//获取WC\u Order对象的实例
$order=wc_get_order(522);
//返回此订单中的运输成本数组。
$order->get_shipping_methods();//与$order->get_items('shipping')相同
//基于订单发货方法的条件函数
如果($order->has_shipping_method('flat_rate')){
//输出格式化的装运方法标题。
echo“装运方法名称:”。$order->get_Shipping_method())。;