Woocommerce - php to get order information

后端 未结 2 1245
后悔当初
后悔当初 2021-02-08 04:28

I\'m trying to get the data associated with an order on the woocommerce plugin (wordpress). Currently, I have written my own plugin that contains the code:



        
2条回答
  •  长情又很酷
    2021-02-08 04:58

    Recently i worked for Export of Orders Data in XML.

    $args = array(
      'post_type' => 'shop_order',
      'post_status' => 'publish',
      'meta_key' => '_customer_user',
      'posts_per_page' => '-1'
    );
    $my_query = new WP_Query($args);
    
    $customer_orders = $my_query->posts;
    
    foreach ($customer_orders as $customer_order) {
     $order = new WC_Order();
    
     $order->populate($customer_order);
     $orderdata = (array) $order;
    
     // $orderdata Array will have Information. for e.g Shippin firstname, Lastname, Address ... and MUCH more.... Just enjoy!
    }
    

提交回复
热议问题