2017-04-09 92 views
0

我目前正在使用Woocommerce,並希望將銷售數據的一些細節轉換爲我使用php和mysql製作的自定義腳本。獲取銷售訂單詳細信息來自Wocommerce

而且這裏是數據的一些細節,我想擺脫Woocomerce的:

  • 訂單號
  • 訂購名稱
  • 訂單日期
  • 訂單項目
  • 訂單總計

任何人都可以幫助我嗎?

回答

1

更新:新增WC 3+兼容性

你需要下面的代碼從訂單獲取銷售信息:

// Get all customer orders 
$customer_orders = wc_get_orders($args = array(
    'numberposts' => -1, 
    'post_status' => array('wc-completed'), // completed order status only 
)); 

// Iterating through each order 
foreach($customer_orders as $customer_order){ 

    // compatibility with WC +3 
    $customer_order_id = method_exists($customer_order, 'get_id') ? $customer_order->get_id() : $customer_order->id; 
    $customer_order_date = method_exists($customer_order, 'get_date_created') ? $customer_order->get_date_created() : $customer_order->post->order_date; 

    echo 'Order ID: ' . $customer_order_id.'<br>'; 
    echo 'Order date: ' . $customer_order_date.'<br>'; 
    echo 'Order Total: ' . $customer_order->get_total().'<br>'; 

    // Iterating through each Item in the order 
    foreach($customer_order->get_items() as $item_id => $item_values){ 
     echo 'Item name: ' . $item_values['name'].'<br>'; 
     echo 'Item quantity: ' . $item_values['qty'].'<br>'; 
     echo 'Item line total: ' . $item_values['line_total'].'<br><br>'; 
    } 
} 

這裏有一個相關的答案:How to get WooCommerce order details

+0

喜感謝它,我的意思是我只需要一些SQL查詢,你有什麼想法嗎? – Riandy

相關問題