【问题标题】:Getting order items list in custom php class woocommerce在自定义 php 类 woocommerce 中获取订单项列表
【发布时间】:2014-10-24 19:32:21
【问题描述】:

在我的自定义类中,我想打印客户订购的商品。 在 wooCommerce 的自定义类中执行此操作的正确方法是什么?

我的代码示例;

$args = array(
      'post_type' => 'shop_order',
      'post_status' => 'wc-processing',
      'meta_key' => '_customer_user',
      'posts_per_page' => '-1', 
    );

    $my_query = new WP_Query($args);
    $customer_orders = $my_query->posts;

    # Loop through orders
    foreach ($customer_orders as $customer_order) :

        $order = new WC_Order($customer_order->id);
        $order->populate($customer_order);
        $this->woOrders[] = (array) $order;

        # User billing address
        $this->billingAddress  = $order->get_formatted_billing_address();
        echo $this->billingAddress;

        # User shipping address
        $this->shippingAddress = $order->get_formatted_shipping_address();
        echo $this->shippingAddress .'<br>';


     endforeach;

谢谢

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    解决办法;

    $items = $order->get_items();
    
        foreach ($items as $item ) :
            var_dump($item);
    endforeach;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 2018-03-16
      • 2020-11-11
      • 2018-02-06
      • 2021-06-10
      • 2021-05-09
      相关资源
      最近更新 更多