我一直在尝试在woocommerce中添加自定义订单状态Shipped。
这里是代码
function add_awaiting_shippped_to_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-order-shipped'] = __('Shipped', 'woocommerce' );
}
}
return $new_order_statuses;
}
function register_shipped_status() {
register_post_status( 'wc-order-shipped', array(
'label' => _x( 'Shipped', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped<span class="count">(%s)</span>', 'woocommerce' )
) );
}
add_action( 'init', array( $plugin_admin_meta_box, 'register_shipped_status') );
add_filter( 'wc_order_statuses', array( $plugin_admin_meta_box, 'add_awaiting_shippped_to_order_statuses') );
[运送状态]在woocommerce中随处可见,并且运行正常
每当我将订单的状态更改为已发货时,订单将成功更新
现在的问题是已发货的订单未显示在订单表中
以下内容可在自定义插件中添加功能性自定义订单状态:
// Register new custom order status
function register_shipped_status() {
register_post_status( 'wc-order-shipped', array(
'label' => _x( 'Shipped', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped<span class="count">(%s)</span>', 'woocommerce' )
) );
}
// Add new custom order status to list of WC Order statuses
function add_awaiting_shippped_to_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-order-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' );
}
}
return $new_order_statuses;
}
// Adding custom status to admin order list bulk actions dropdown
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$new_actions = array();
// Add new order status before processing
foreach ($actions as $key => $action) {
$new_actions[$key] = $action;
if ('mark_processing' === $key) {
$actions['mark_order-shipped'] = __( 'Mark Shipped', 'woocommerce' );
}
}
return $actions;
}
add_action( 'init', array($plugin_admin_meta_box, 'register_shipped_status') );
add_filter( 'wc_order_statuses', array($plugin_admin_meta_box, 'add_awaiting_shippped_to_order_statuses' );
add_filter( 'bulk_actions-edit-shop_order', array($plugin_admin_meta_box, 'custom_dropdown_bulk_actions_shop_order'), 20, 1 );