【问题标题】:Get Local pickup plus details from the order in Woocommerce从 Woocommerce 中的订单中获取本地取货和详细信息
【发布时间】:2019-08-20 11:30:04
【问题描述】:

在 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】:

    有关订单商品的运输详情,请参阅:"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>';
    }
    

    关于自定义运输元数据:

    您可以使用位于任何自定义元数据对象中的自定义元 "key" 中的 WC_Data 方法 get_meta() 访问它,例如:

    $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 官方插件,但我找不到 php 的基本用法示例。它具有用户级别的解释设置。 docs.woocommerce.com/document/local-pickup-plus
    • 我以为它是默认的附加插件,但似乎不是。对不起。
    • 它不在项目元数据上。它正在订购中。有没有捷径,或者我应该尝试从订单数组中获取它? 'meta_data' => 数组 ( 0 => WC_Meta_Data::__set_state(array( 'current_data' => 数组 ('id' => 2768, 'key' => '_pickup_location_id', 'value' => '7254', ) , 'data' => 数组 ('id' => 2768, 'key' => '_pickup_location_id', 'value' => '7254', ), ' ...
    • 我更新了我上面提到的特定插件的答案。
    猜你喜欢
    • 2017-01-17
    • 2020-02-08
    • 1970-01-01
    • 2014-05-15
    • 2020-09-28
    • 1970-01-01
    • 2018-05-20
    • 2019-02-28
    • 2018-02-16
    相关资源
    最近更新 更多