将自定义订单状态添加到 WooCommerce 管理员订单列表中的筛选菜单
Add custom order status to filter menu in WooCommerce Admin Orders list
我目前正在尝试向 WooCommerce 管理员订单列表添加新的快速过滤器 (subsubsub):
我有一个名为 "wc-test-accepted" 的自定义订单状态。如何为我的自定义订单状态添加一个新的快速过滤器到顶部?
To get the related filter to your custom order status "wc-test-accepted" in the orders statuses menu filter, you just need to change the status of at least one order and the filter will appear.
以下代码将添加新的自定义订单状态 "wc-test-accepted"(已接受):
// Register new custom order status
add_action('init', 'register_custom_order_statuses');
function register_custom_order_statuses() {
register_post_status('wc-test-accepted ', array(
'label' => __( 'Accepted', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Accepted <span class="count">(%s)</span>', 'Accepted <span class="count">(%s)</span>')
));
}
// Add new custom order status to list of WC Order statuses
add_filter('wc_order_statuses', 'add_custom_order_statuses');
function add_custom_order_statuses($order_statuses) {
$new_order_statuses = array();
// add new order status before processing
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ('wc-processing' === $key) {
$new_order_statuses['wc-test-accepted'] = __('Accepted', 'woocommerce' );
}
}
return $new_order_statuses;
}
// Adding new custom status to admin order list bulk dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 50, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$new_actions = array();
// add new order status before processing
foreach ($actions as $key => $action) {
if ('mark_processing' === $key)
$new_actions['mark_test-accepted'] = __( 'Change status to Accepted', 'woocommerce' );
$new_actions[$key] = $action;
}
return $new_actions;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
一旦您将至少一个订单更改为 "Accepted" 订单状态,它就会显示为过滤器:
我目前正在尝试向 WooCommerce 管理员订单列表添加新的快速过滤器 (subsubsub):
我有一个名为 "wc-test-accepted" 的自定义订单状态。如何为我的自定义订单状态添加一个新的快速过滤器到顶部?
To get the related filter to your custom order status "wc-test-accepted" in the orders statuses menu filter, you just need to change the status of at least one order and the filter will appear.
以下代码将添加新的自定义订单状态 "wc-test-accepted"(已接受):
// Register new custom order status
add_action('init', 'register_custom_order_statuses');
function register_custom_order_statuses() {
register_post_status('wc-test-accepted ', array(
'label' => __( 'Accepted', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Accepted <span class="count">(%s)</span>', 'Accepted <span class="count">(%s)</span>')
));
}
// Add new custom order status to list of WC Order statuses
add_filter('wc_order_statuses', 'add_custom_order_statuses');
function add_custom_order_statuses($order_statuses) {
$new_order_statuses = array();
// add new order status before processing
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ('wc-processing' === $key) {
$new_order_statuses['wc-test-accepted'] = __('Accepted', 'woocommerce' );
}
}
return $new_order_statuses;
}
// Adding new custom status to admin order list bulk dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 50, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$new_actions = array();
// add new order status before processing
foreach ($actions as $key => $action) {
if ('mark_processing' === $key)
$new_actions['mark_test-accepted'] = __( 'Change status to Accepted', 'woocommerce' );
$new_actions[$key] = $action;
}
return $new_actions;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
一旦您将至少一个订单更改为 "Accepted" 订单状态,它就会显示为过滤器: