从 Woocommerce 中的订单中获取本地取件和详细信息
Get Local pickup plus details from the order in Woocommerce
在 Woocommerce 中,我只想获取 "local pickup" 送货详细信息以显示在自定义电子邮件中。我尝试了以下功能,但它们没有显示 "local pickup" 的任何内容。
我可以使用哪个函数来获取 "local pickup" 信息?
我尝试了以下 WC_Order
方法但没有成功:
$order->get_shipping_address_1()
$order->get_formatted_shipping_address()
编辑:
抱歉我没有提到,但我正在使用 Local Pickup Plus 插件
编辑 2:
这就是我获取 Local Pickups Plus 插件 docs.woocommerce 的本地取件信息的方式 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']
有关订单商品的运输详情,请参阅:""
要从 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>';
}
Regarding the custom shipping metadata:
You can access it using the WC_Data
method get_meta()
from the custom meta "key
" located in any custom meta data Objects, like:
$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 );
订单相关话题:
添加 - 对于 Local Pickup Plus 插件
您似乎正在使用 Local Pickup Plus plugin,它在运输线路中添加了特定的自定义元数据。
// 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');
}
在 Woocommerce 中,我只想获取 "local pickup" 送货详细信息以显示在自定义电子邮件中。我尝试了以下功能,但它们没有显示 "local pickup" 的任何内容。
我可以使用哪个函数来获取 "local pickup" 信息?
我尝试了以下 WC_Order
方法但没有成功:
$order->get_shipping_address_1()
$order->get_formatted_shipping_address()
编辑:
抱歉我没有提到,但我正在使用 Local Pickup Plus 插件
编辑 2:
这就是我获取 Local Pickups Plus 插件 docs.woocommerce 的本地取件信息的方式 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']
有关订单商品的运输详情,请参阅:"
要从 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>';
}
Regarding the custom shipping metadata:
You can access it using the
WC_Data
methodget_meta()
from the custom meta "key
" located in any custom meta data Objects, like:$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 );
订单相关话题:
添加 - 对于 Local Pickup Plus 插件
您似乎正在使用 Local Pickup Plus plugin,它在运输线路中添加了特定的自定义元数据。
// 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');
}