2016-09-27 77 views
3

我想在WooCommerce Admin Dashboard Stats小部件中包含自定義訂單狀態的詳細信息。我在wc-processing之後設置了2個自定義訂單狀態。在Admin Dashboard Stats小部件中添加自定義訂單狀態

訂單流程付款成功後:
wc-processing =>wc-awaiting-shipment =>wc-dispatched =>wc-completed

由於awaiting shipmentdispatched是定製訂單狀態,WooCommerce統計插件是不是反映了總銷售金額的訂單。問題是,我有很多訂單wc-dispatchedwc-awaiting-shipment狀態。

這是我已經習慣了這種註冊的客戶訂單狀態代碼:

/** 
* 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:我現在外出旅遊,所以現在還不能對其進行測試,將能夠8小時後更新。並抱歉不通知。 –

回答

5

首先,我使用2次相同的鉤子重新訪問了您的代碼。所以,知道你有2層上鉤的功能,而不是4

要回答你的問題:是的,有我剛纔測試了將包括在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頁面顯示0項**。我註釋掉最後一行(即'add_filter')項目計數顯示正確。如何解決這個問題?請檢查此[截圖](http://screencast.com/t/I2pzk5jw9)。 –

+0

@RaunakGupta我試圖找出一些竅門,使其工作......但我暫時沒有得到它。 – LoicTheAztec

相關問題