2017-07-10 19 views
1

こんにちは私のアカウントテンプレートのWooCommerceテンプレート "orders.php"の中にカスタム注文クエリを作成したいと思います。テンプレート内のWooCommerce 3でカスタムクエリを作成します。myaccount/orders.php

あなたは次のように「私のテーマ/ woocommerce /テンプレート/マイアカウント/ orders.php」

クエリがある編集テンプレート。しかし、私はWoocommerce 3.0.xで動作しません

$customer_orders = get_posts(array( 
    'numberposts' => $order_count, 
    'meta_key' => '_customer_user', 
    'meta_value' => get_current_user_id(), 
    'post_type' => 'shop_order', 
    'post_status' => 'publish', 
    'date_query' => array(
    array(
     'after' => date('Y-m-d', strtotime($from)), 
     'before' => date('Y-m-d', strtotime($to. ' + 1 days')) 
    ), 
), 
)); 

何が問題なのですか?

おかげであなたはプラグイン

に直接Overriding WooCommerce Templates via your Themeすべきではなく、

答えて

2

まず、このクエリでの主な問題は、非常に具体的であるWooCommerce注文に関するpost_status、から来ています。

## DEFINING VARIABLES, JUST FOR TESTING ## 
    $order_count = -1; 
    $from = '2016/04/08'; 
    $to = '2017/02/02'; 

だからあなたの作業テストコードは次のようになります。

$customer_orders = get_posts(array(
    'numberposts' => -1, 
    'meta_key' => '_customer_user', 
    'meta_value' => get_current_user_id(), 
    'post_type' => 'shop_order', 
    # HERE below set your desired Order statusses 
    'post_status' => array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed'), 
    'date_query' => array(array(
     'after' => date('Y-m-d', strtotime($from)), 
     'before' => date('Y-m-d', strtotime($to . ' + 1 days')), 
     'inclusive' => true, // If you want a before date to be inclusive, 
    )), 
)); 

それとも、また専用のWooCommerceの受注はあなたにすべてのWC_Orderオブジェクトの代わりに、WP_Postを与えるwc_get_orders()機能の代わりに使用することができますオブジェクト、このように:

$customer_orders = wc_get_orders(array(
    'numberposts' => -1, 
    'meta_key' => '_customer_user', 
    'meta_value' => get_current_user_id(), 
    ## NOT NEEDED ## 'post_type' => 'shop_order', 
    'post_status' => array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed'), 
    'date_query' => array(array(
     'after' => date('Y-m-d', strtotime($from)), 
     'before' => date('Y-m-d', strtotime($to . ' + 1 days')), 
     'inclusive' => true, // If you want a before date to be inclusive, 
    )), 
)); 

はその後大丈夫直接各$順序オブジェクト上のすべてのWC_Order方法] 2 ...

+0

を使用することができます、おかげで、私は正常に働いていました。どうもありがとうございました。 :) –

関連する問題