我需要创建一个函数,将函数返回给我的一个插件WooCommerce Dymo Print.它需要$order_id,$label和$object. $object是我需要返回值的字段.
我创建了以下代码:
add_filter('wc_dymo_order_function', 'wpf_dymo_order_output',10,3);
function wpf_dymo_order_output( $order_id, $label, $object ) {
if($label=='shipping' && $object='DEL_DATE') {
//Get order from order ID
$order=wc_get_order($order_id);
$del_date='';
$order_data = $order->get_data(); // The Order data
$order_del_date = $order_data['delivery_date'];
//Return a list (string) of all product inside this order, make sure it's well formatted before printing.
return $order_del_date;
} else {
//Return order_id if is not correct label and object
return '';
}
}
它似乎不起作用,我认为这是因为delivery_date嵌套在一个数组中,我没有正确地获取它.
元数据看起来应该是这样的.
Array
(
[31040763] => Array
(
[shipment_id] => 31040763
[tracktrace] => 3SMYPA000000000
[shipment] => Array
(
[barcode] => 3SMYPA000000000
[pickup] => Array
(
[postal_code] => XXXAA
[street] => STRAAT
[city] => STAD
[number] => XX
[location_name] => Gamma
)
[options] => Array
(
[signature] => 0
[delivery_date] => 2018-03-10 00:00:00
)
)
)
)
delivery_date是我需要返回的地方
解决方法:
$order=wc_get_order($order_id);
$order_data = $order->get_Meta('_shipments');
$final_array = array_values($order_data);
$order_del_date = $final_array[0]['options']['delivery_date'];
return $order_del_date;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。