2016-09-27 19 views
3

カスタム注文ステータスの詳細をWooCommerce Admin Dashboard Statsウィジェットに含めたいと思います。 wc-processingの2つの注文ステータスを設定しました。成功した支払の後管理ダッシュボードの統計情報ウィジェットにカスタム注文ステータスを追加する

ご注文の流れは次のとおりです。
wc-processing =>wc-awaiting-shipment =>wc-dispatched =>wc-completed

awaiting shipmentdispatchedカスタムオーダー状態であるとして、WooCommerceは統計ウィジェットは、総売上高におけるそれらの注文を反映していません。問題は、多くの注文があることです。wc-dispatchedのステータスがあります。

/** 
* Register new status 
* Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/ 
* */ 
function register_awaiting_shipment_order_status() { 
    register_post_status('wc-awaiting-shipment', array(
     'label' => 'Awaiting Shipment', 
     'public' => true, 
     'exclude_from_search' => false, 
     'show_in_admin_all_list' => true, 
     'show_in_admin_status_list' => true, 
     'label_count' => _n_noop('Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>') 
    )); 
} 

add_action('init', 'register_awaiting_shipment_order_status'); 

// Add to list of WC Order statuses 
function add_awaiting_shipment_to_order_statuses($order_statuses) { 

    $new_order_statuses = array(); 

    // add new order status after processing 
    foreach ($order_statuses as $key => $status) { 
     $new_order_statuses[$key] = $status; 
     if ('wc-processing' === $key) { 
      $new_order_statuses['wc-awaiting-shipment'] = 'Awaiting shipment'; 
     } 
    } 
    return $new_order_statuses; 
} 

add_filter('wc_order_statuses', 'add_awaiting_shipment_to_order_statuses'); 

/** 
* Register new status 
* Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/ 
* */ 
function register_dispatched_order_status() { 
    register_post_status('wc-dispatched', array(
     'label' => 'Dispatched', 
     'public' => true, 
     'exclude_from_search' => false, 
     'show_in_admin_all_list' => true, 
     'show_in_admin_status_list' => true, 
     'label_count' => _n_noop('Dispatched <span class="count">(%s)</span>', 'Dispatched <span class="count">(%s)</span>') 
    )); 
} 

add_action('init', 'register_dispatched_order_status'); 

// Add to list of WC Order statuses 
function add_dispatched_to_order_status($order_status) { 

    $new_order_statuses = array(); 

    // add new order status after processing 
    foreach ($order_status as $key => $status) { 

     $new_order_statuses[$key] = $status; 

     if ('wc-awaiting-shipment' === $key) { 
      $new_order_statuses['wc-dispatched'] = 'Dispatched'; 
     } 
    } 

    return $new_order_statuses; 
} 

add_filter('wc_order_statuses', 'add_dispatched_to_order_status'); 

Woocommerce Status Dashboard Widgets

どのように私はこれを達成することができます

これは私がこのカスタムオーダーステータスを登録するために使用したコードのですか?

ありがとうございました。

+0

@LoicTheAztec:私は今、旅行してるので、今それをテストすることはできません、8hr後に更新することができます。通知しなかったことを申し訳ありません。 –

答えて

5

まず、同じフックを2回使用する場合のコードを再訪しました。ですから、あなたの質問に答えるために代わり4

の2夢中な機能を持って知っている:YES WooCommerce管理ダッシュボードにカスタムステータスと注文が含まれます、私はちょうどテストした作業管理のフックがあります統計ウィジェット:woocommerce_reports_get_order_report_data_args hook。ここで

このコードされています

// Register new status 
function register_custom_order_statuses() { 
    register_post_status('wc-awaiting-shipment', array(
     'label' => 'Awaiting Shipment', 
     'public' => true, 
     'exclude_from_search' => false, 
     'show_in_admin_all_list' => true, 
     'show_in_admin_status_list' => true, 
     'label_count' => _n_noop('Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>') 
    )); 

    register_post_status('wc-dispatched', array(
     'label' => 'Dispatched', 
     'public' => true, 
     'exclude_from_search' => false, 
     'show_in_admin_all_list' => true, 
     'show_in_admin_status_list' => true, 
     'label_count' => _n_noop('Dispatched <span class="count">(%s)</span>', 'Dispatched <span class="count">(%s)</span>') 
    )); 
} 
add_action('init', 'register_custom_order_statuses'); 


// Add to list of WC Order statuses 
function add_custom_order_statuses($order_statuses) { 
    $new_order_statuses = array(); 

    // add new order status after processing 
    foreach ($order_statuses as $key => $status) { 
     $new_order_statuses[$key] = $status; 
     if ('wc-processing' === $key) { 
      $new_order_statuses['wc-awaiting-shipment'] = 'Awaiting shipment'; 
      $new_order_statuses['wc-dispatched'] = 'Dispatched'; 
     } 
    } 
    return $new_order_statuses; 
} 
add_filter('wc_order_statuses', 'add_custom_order_statuses'); 


// Admin reports for custom order status 
function wc_reports_get_order_custom_report_data_args($args) { 
    $args['order_status'] = array('completed', 'processing', 'on-hold', 'awaiting-shipment', 'dispatched'); 
    return $args; 
}; 
add_filter('woocommerce_reports_get_order_report_data_args', 'wc_reports_get_order_custom_report_data_args'); 

このコードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルやも任意のプラグインファイルになります。

コードはテストされ、完全に機能します。


参考文献:

+0

ありがとうございます。 :) –

+0

こんにちは@LoicTheAztec私は 'woocommerce_reports_get_order_report_data_args'フィルタが注文合計を完全に計算しているのを見ましたが、** WooCommerce wc-reportsページの**アイテム**を示しています。最後の行をコメントアウトします(つまり、 'add_filter')。アイテム数が正しく表示されています。これを修正するには?この[screenshot](http://screencast.com/t/I2pzk5jw9)を確認してください。 –

+0

@RaunakGupta私はそれを動作させるためにいくつかのトリックを見つけようとしました...しかし、私はそれを現時点では得られませんでした。 – LoicTheAztec

関連する問題