在Woocommerce中,我只想在自定义电子邮件中显示"本地取件"运输详细信息。我尝试了下面的功能,但它们没有显示任何"本地拾取"的内容。
我可以使用哪个功能来获取"本地取件"信息?
我尝试了以下WC_Order
方法,但没有成功:
$order->get_shipping_address_1()
$order->get_formatted_shipping_address()
编辑:
抱歉,我没有提到这一点,但我正在使用本地皮卡加插件
编辑 2:
这就是我获取本地取货加插件 docs.woocommerce.com/document/local-pickup-plus 的本地取货信息的方式,该插件将元数据放入主订单变量。
$order = wc_get_order( $order_id );
foreach ($order->get_data() as $key => $value):
if ($key==='shipping_lines'):
foreach ($value as $k=>$v):
$a = $v->get_meta_data();
foreach ($a as $x=>$y):
$t = $y->get_data();
$mykey = $t['key'] ;
$pickup["$mykey"] = $t['value'];
endforeach;
endforeach;
endif;
endforeach;
然后,您可以使用以下变量:
$pickup['_pickup_location_name']
$pickup['_pickup_location_address']['address_1']
$pickup['_pickup_location_phone']['address_2']
$pickup['_pickup_location_address']['postcode']
$pickup['_pickup_location_address']['city']
$pickup['_pickup_location_address']['state'] $pickup['_pickup_location_address']['country']
$pickup['_pickup_location_phone']
$pickup['_pickup_date']
$pickup['_pickup_minimum_hours']
对于订单商品的运输详细信息,请参阅:"在WooCommerce 3中获取订单运输方式详细信息">
若要从WC_Order
对象定位订单装运行详细信息,可以使用以下代码:
// Loop though order items shipping
foreach( $order->get_shipping_methods() as $item_id => $item ){
$shipping_item_name = $item->get_name();
$shipping_item_type = $item->get_type();
$shipping_method_title = $item->get_method_title();
$shipping_method_id = $item->get_method_id();
$shipping_method_instance_id = $item->get_instance_id();
$shipping_method_total = $item->get_total();
$shipping_method_total_tax = $item->get_total_tax();
$shipping_method_taxes = $item->get_taxes();
// Get custom meta-data
$formatted_meta_data = $item->get_formatted_meta_data( ' ', true );
// Displaying the row custom meta data Objects (just for testing)
echo '<pre>'; print_r($formatted_meta_data); echo '</pre>';
}
关于自定义运输元数据:
您可以使用
WC_Data
方法访问它,该方法get_meta()
位于任何自定义元数据对象中的自定义元"key
">,例如:$value = $item->get_meta('the_custom_key'); // 'the_custom_key' need to be replaced by the meta "key".
注意:在大多数 WooCommerce 电子邮件模板和电子邮件通知相关钩子中,您可以使用全局包含的WC_Order
对象。如果没有,您可以从订单 ID 中获取它,例如:
$order = wc_get_order( $order_id );
订单相关线程:
- 在WooCommerce 3中获取订单运输方式详细信息
- 在Woocommerce中获取订单项目和WC_Order_Item_Product 3
- 如何获取WooCommerce订单详细信息
添加 - 用于本地拾取加插件
您似乎正在使用本地取件加插件,该插件在运输公司中添加了特定的自定义元数据。
// Loop though order items shipping
foreach( $order->get_shipping_methods() as $item_id => $item ){
$location_id = $item->get_meta('_pickup_location_id');
$location_name = $item->get_meta('_pickup_location_name');
$location_address = $item->get_meta('_pickup_location_address'); // Array
$location_address_1 = $location_address['address_1'];
$location_address_2 = $location_address['address_2'];
$location_postcode = $location_address['postcode'];
$location_city = $location_address['city'];
$location_state = $location_address['state'];
$location_country = $location_address['country'];
$location_phone = $item->get_meta('_pickup_location_phone');
$pickup_date = $item->get_meta('_pickup_date');
$pickup_min_hours = $item->get_meta('_pickup_minimum_hours');
}