在Admin Dashboard Stats Widget中添加自定义订单状态 [英] Adding custom order statuses in Admin Dashboard Stats Widget
问题描述
我想在WooCommerce Admin Dashboard Stats小部件中包含来自自定义订单状态的详细信息.我设置了2个自定义订单状态,该状态在 wc-processing
之后.
成功付款后的订单流为:
wc-processing
=>wc-awaiting-shipment
=>wc-dispatched
=>wc完成
.
由于 待发货
和 已发货
是自定义订单状态,因此"WooCommerce统计信息"小部件不会在总销售额.问题是我有很多订单,状态为 wc-dispatched
和 wc-awaiting-shipment
.>
这是我用来注册此自定义订单状态的代码:
/***注册新状态*教程:http://www.sellwithwp.com/woocommerce-custom-order-status-2/* */函数register_awaiting_shipment_order_status(){register_post_status('wc-awaiting-shipment',array('标签'=>'等待发货','public'=>真的,'exclude_from_search'=>错误的,'show_in_admin_all_list'=>真的,'show_in_admin_status_list'=>真的,'label_count'=>_n_noop('正在等待装运< span class =计数">(%s)</span>','正在等待装运< span class ='count'>(%s)</span>')));}add_action('init','register_awaiting_shipment_order_status');//添加到WC订单状态列表函数add_awaiting_shipment_to_order_statuses($ order_statuses){$ new_order_statuses = array();//处理后添加新的订单状态foreach($ order_statuses as $ key => $ status){$ new_order_statuses [$ key] = $ status;如果('wc-processing'=== $ key){$ new_order_statuses ['wc-awaiting-shipment'] ='正在等待发货';}}返回$ new_order_statuses;}add_filter('wc_order_statuses','add_awaiting_shipment_to_order_statuses');/***注册新状态*教程:http://www.sellwithwp.com/woocommerce-custom-order-status-2/* */函数register_dispatched_order_status(){register_post_status('wc-dispatched',array('标签'=>已分派",'public'=>真的,'exclude_from_search'=>错误的,'show_in_admin_all_list'=>真的,'show_in_admin_status_list'=>真的,'label_count'=>_n_noop('Dispatched< span class ="count">(%s)</span>','Dispatched< span class ='count'>(%s)</span>')));}add_action('init','register_dispatched_order_status');//添加到WC订单状态列表函数add_dispatched_to_order_status($ order_status){$ new_order_statuses = array();//处理后添加新的订单状态foreach($ order_status as $ key => $ status){$ new_order_statuses [$ key] = $ status;if('wc-awaiting-shipment'=== $ key){$ new_order_statuses ['wc-dispatched'] ='已分配';}}返回$ new_order_statuses;}add_filter('wc_order_statuses','add_dispatched_to_order_status');
我该如何实现?
谢谢.
首先,我使用2个相同的钩子重新访问了您的代码.所以知道您有2个钩子函数,而不是4个.
要回答您的问题:是的,我刚刚测试了一个有效的管理员钩子,该钩子将在WooCommerce管理员仪表板统计窗口小部件中包含具有您的自定义状态的订单:
此代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.
该代码已经过测试并且功能齐全.
参考文献:
I would like to include details from custom order status in WooCommerce Admin Dashboard Stats widget. I have set 2 custom order status which comes after
wc-processing
.Order Flow after successful payment is:
wc-processing
=>wc-awaiting-shipment
=>wc-dispatched
=>wc-completed
.As
awaiting shipment
anddispatched
are custom order statuses, WooCommerce stats widget is not reflecting those orders in total sales amount. The problem is that I have many orders withwc-dispatched
andwc-awaiting-shipment
statuses.This is code that I have used to register this custom order statuses:
/** * 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');
How can I achieve this?
Thanks.
解决方案First, I have revisited your code as you where using 2 times the same hooks. So know you have 2 hooked functions instead of 4.
To answer to your question: YES there is a working admin hook that I have just tested that will include orders with your custom statuses in the WooCommerce Admin Dashboard Stats widget:
woocommerce_reports_get_order_report_data_args
hook.Here is this code:
// 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');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
References:
- WooCommerce source class WC_Admin_Report - get_order_report_data()
- Custom order status aren't displayed on the customer my account order history
这篇关于在Admin Dashboard Stats Widget中添加自定义订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!