2017-03-07 8 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; 
    } 

このコードを試してください。

関連する問題