2016-09-27 81 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

相关问题