在 Woocommerce 管理员订单列表中显示具有 "all" 自定义状态的订单
Display orders with a custom status for "all" in Woocommerce admin orders list
我使用此代码创建了几个自定义订单状态
register_post_status( 'wc-arrival-shipment', array(
'label' => 'Shipped but not paid',
'public' => false,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Shipped but not paid<span class="count">(%s)</span>', 'Shipped but not paid <span class="count">(%s)</span>' )
) );
除所有订单列表外,其他都运行好。它显示了正确的全部 (3) 计数,但在列表中您只会看到 1 个订单,并且不会显示已更新为新自定义订单状态的所有其他 2 个订单。仅显示 1 个订单,仅保留订单
要解决这个问题,您还需要在 wc_order_statuses 过滤器挂钩中添加您的自定义订单…
同时,将其显示在批量操作下拉列表中会很有用。
完整代码:
// Add custom status to order list
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-arrival-shipment', array(
'label' => _x( 'Shipped but not paid', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'label_count' => _n_noop( 'Shipped but not paid<span class="count">(%s)</span>', 'Shipped but not paid <span class="count">(%s)</span>' )
) );
}
// Add custom status to order edit page drop down (and displaying orders with this custom status in the list)
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-arrival-shipment'] = _x( 'Shipped but not paid', 'Order status', 'woocommerce' );
return $order_statuses;
}
// Adding custom status to admin order list bulk actions dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_arrival-shipment'] = __( 'Mark Shipped but not paid', 'woocommerce' );
return $actions;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
我使用此代码创建了几个自定义订单状态
register_post_status( 'wc-arrival-shipment', array(
'label' => 'Shipped but not paid',
'public' => false,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Shipped but not paid<span class="count">(%s)</span>', 'Shipped but not paid <span class="count">(%s)</span>' )
) );
除所有订单列表外,其他都运行好。它显示了正确的全部 (3) 计数,但在列表中您只会看到 1 个订单,并且不会显示已更新为新自定义订单状态的所有其他 2 个订单。仅显示 1 个订单,仅保留订单
要解决这个问题,您还需要在 wc_order_statuses 过滤器挂钩中添加您的自定义订单…
同时,将其显示在批量操作下拉列表中会很有用。
完整代码:
// Add custom status to order list
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-arrival-shipment', array(
'label' => _x( 'Shipped but not paid', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'label_count' => _n_noop( 'Shipped but not paid<span class="count">(%s)</span>', 'Shipped but not paid <span class="count">(%s)</span>' )
) );
}
// Add custom status to order edit page drop down (and displaying orders with this custom status in the list)
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-arrival-shipment'] = _x( 'Shipped but not paid', 'Order status', 'woocommerce' );
return $order_statuses;
}
// Adding custom status to admin order list bulk actions dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_arrival-shipment'] = __( 'Mark Shipped but not paid', 'woocommerce' );
return $actions;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。