获取本地提货以及Woocommerce订单中的详细信息

问题描述 投票:1回答:1

在Woocommerce中,我只想在自定义电子邮件中显示“本地取件”送货详细信息。我试过下面的功能,但他们没有显示“本地拾取”的任何内容。

我可以用哪种功能获取“本地取件”信息?

我尝试了以下WC_Order方法没有成功:

  • $order->get_shipping_address_1()
  • $order->get_formatted_shipping_address()

编辑:

对不起,我没有提到,但我使用的是Local Pickup Plus插件


编辑2:

这就是我获取Local Pickups Plus插件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']
php wordpress woocommerce orders shipping-method
1个回答
1
投票

有关订单商品的运费详情,请参阅:“Get orders shipping method details in 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 );

订单相关主题:


添加 - 适用于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');
}
© www.soinside.com 2019 - 2024. All rights reserved.