2017-04-12 110 views
1

我有一些代碼,它向我的functions.php中的[sales-list]簡碼輸出已完成訂單的列表。它在Woocommerce 3.0更新之前完美運行,但由於(我假設)3.0中的新CRUD類已停止工作。Woocommerce更新自定義訂單查詢爲3.0

問題是:我該如何適應這一點以適應新的類?或者如果這不是問題,還有什麼可能改變?

下面的代碼:

/* Sales List */ 
function saleslist_shortcode() { 
    global $woocommerce; 
    $args = array(
     'post_type' => 'shop_order', 
     'post_status' => 'publish', 
     'posts_per_page' => -1, 
     'tax_query' => array(
      array(
       'taxonomy' => 'shop_order_status', 
       'field' => 'slug', 
       'terms' => array(
        'completed' 
      ) 
     ) 
    ) 
); 

    $loop = new WP_Query($args); ?> 

    <div class="sales-list"> 
    <?php 
    while ($loop->have_posts()): 
     $loop->the_post(); 
     $order_id = $loop->post->ID; 
     $order = new WC_Order($order_id); ?> 
     <article> 
     <h6 class="mtn ptn">Order #<?php echo $order_id; ?> &mdash; <time datetime="<?php the_time('c'); ?>"><?php echo the_time('d/m/Y'); ?></time></h6> 
      <table cellspacing="0" cellpadding="2"> 
       <tbody> 
        <?php echo $order->email_order_items_table(array(
         'show_sku'  => true, 
         'show_image' => false, 
         'image_size' => array(32, 32), 
         'plain_text' => $plain_text, 
         'sent_to_admin' => true 
        )); ?> 
       </tbody> 
      </table> 
     <div style="clear:both;"></div> 
     </article> 
    <?php endwhile; ?> 
    </div> 
    <?php 
} 

add_shortcode('sales-list', 'saleslist_shortcode'); 
+0

選中此功能「$ order-> email_order_items_table」 –

+0

該方法已過時,但仍存在。我相信問題在於分類法不用於確定訂單狀態。這是一段時間後的狀態。 – helgatheviking

回答

1

我可能會與改變post_type參數"post_type" => array_keys(wc_get_order_statuses())開始。通過「發佈狀態」處理稅務查詢作爲訂單狀態。

我想我會建議切換到wc_get_orders()。這是我現在最好的猜測。請記住,如果你沒有使用WC3.0,這將會有一個致命的錯誤...即:它不兼容。

/* Sales List */ 
function saleslist_shortcode() { 

    $args = array(
     'limit' => -1, 
     'status' => array('wc-completed'), 
     'type' => array('shop_order') 
); 

    $orders = wc_get_orders($args); 

    ob_start(); 

    if($orders){ ?> 

    <div class="sales-list"> 

     <?php foreach($orders as $order){ ?> 

     <article> 

      <h6 class="mtn ptn"><?php printf(__('Order #%s', 'your-plugin'), $order->get_order_number()); ?> <?php printf('<time datetime="%s">%s</time>', $order->get_date_created()->format('c'), wc_format_datetime($order->get_date_created())); ?></h6> 

      <table> 
       <thead> 
        <tr> 
         <th class="td"><?php _e('Product', 'your-plugin'); ?></th> 
         <th class="td"><?php _e('Quantity', 'your-plugin'); ?></th> 
         <th class="td"><?php _e('Price', 'your-plugin'); ?></th> 
        </tr> 
       </thead> 
       <tbody> 
        <?php echo wc_get_email_order_items($order, array(
         'show_sku'  => false, 
         'show_image' => false, 
         'image_size' => array(32, 32), 
         'plain_text' => false, 
         'sent_to_admin' => false, 
        )); ?> 
       </tbody> 
      </table> 

     </article> 

     <?php } ?> 

    </div> 
    <?php } 

    return ob_get_clean(); 

} 
add_shortcode('sales-list', 'saleslist_shortcode'); 
+0

完美無缺 - 謝謝! –

相關問題