dongzhi8487 2014-10-24 11:10
浏览 149

获取自定义php类woocommerce中的订单商品列表

In my custom class I would like to print the items ordered by the customer. What is the right way of doing this in a custom class with wooCommerce?

Example of my code;

$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;

Thanks

  • 写回答

1条回答 默认 最新

  • drep94225 2014-10-24 11:32
    关注

    The solution;

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度