2017-03-07 151 views
2

我想獲取當前用戶在插件功能中所做的所有訂單。如何獲取woocommerce中當前用戶的所有訂單

我使用這個:

function get_all_orders(){ 
     $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
      'numberposts' => $order_count, 
      'meta_key' => '_customer_user', 
      'meta_value' => get_current_user_id(), 
      'post_type' => wc_get_order_types('view-orders'), 
      'post_status' => array_keys(wc_get_order_statuses()) 
     ))); 
    return $customer_orders; 
    } 

這種運作良好,裏面的主題,但裏面自定義插件不返回任何東西。 我做錯了什麼?我應該先撥打一些WooCommerce課程嗎?

+0

我已經在一個插件中測試了你的代碼,激活了它,並且在前端沒有任何需求的情況下完美運行。你的問題在其他地方... – LoicTheAztec

回答

0
if (!class_exists('WooCommerce')) : 
     require ABSPATH . 'wp-content/plugins/woocommerce/woocommerce.php'; 
     $orders = get_all_orders(); 
    endif; 

    function get_all_orders() { 
     $customer_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
      'numberposts' => -1, 
      'meta_key' => '_customer_user', 
      'meta_value' => get_current_user_id(), 
      'post_type' => wc_get_order_types('view-orders'), 
      'post_status' => array_keys(wc_get_order_statuses()) 
       ))); 
     return $customer_orders; 
    } 

試試這個代碼。

相關問題