WooCommerce 自定义订单状态并添加此状态批量操作下拉
WooCommerce custom order status and add this status bulk action drop down
我已经使用下面的代码在 WooCommerce 中添加了自定义订单状态,它正在运行。如何在订单列表页面的 WooCommerce 批量操作下拉列表中添加此订单状态。我想批量更改订单状态。
// Register new order status
function register_on_production_order_status() {
register_post_status( 'wc-on-production', array(
'label' => 'On Production',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'On Production (%s)', 'On Production (%s)' )
) );
}
add_action( 'init', 'register_on_production_order_status' );
// Add to list of WC Order statuses in single order page
function add_on_production_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-on-production'] = 'On Production';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_on_production_to_order_statuses' );
// Add a bulk action to Orders bulk actions dropdown
add_filter('bulk_actions-edit-shop_order', 'status_orders_bulk_actions');
function status_orders_bulk_actions($bulk_actions) {
$bulk_actions['on-production'] = __('Change to on production');
return $bulk_actions;
}
// Process the bulk action from selected orders
add_filter('handle_bulk_actions-edit-shop_order', 'status_bulk_action_edit_shop_order', 10, 3);
function status_bulk_action_edit_shop_order($redirect_to, $action, $post_ids) {
if ($action === 'on-production') {
foreach ($post_ids as $post_id) {
$order = wc_get_order($post_id);
$order->update_status('on-production');
}
}
return $redirect_to;
}
我已经使用下面的代码在 WooCommerce 中添加了自定义订单状态,它正在运行。如何在订单列表页面的 WooCommerce 批量操作下拉列表中添加此订单状态。我想批量更改订单状态。
// Register new order status
function register_on_production_order_status() {
register_post_status( 'wc-on-production', array(
'label' => 'On Production',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'On Production (%s)', 'On Production (%s)' )
) );
}
add_action( 'init', 'register_on_production_order_status' );
// Add to list of WC Order statuses in single order page
function add_on_production_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-on-production'] = 'On Production';
}
}
return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_on_production_to_order_statuses' );
// Add a bulk action to Orders bulk actions dropdown
add_filter('bulk_actions-edit-shop_order', 'status_orders_bulk_actions');
function status_orders_bulk_actions($bulk_actions) {
$bulk_actions['on-production'] = __('Change to on production');
return $bulk_actions;
}
// Process the bulk action from selected orders
add_filter('handle_bulk_actions-edit-shop_order', 'status_bulk_action_edit_shop_order', 10, 3);
function status_bulk_action_edit_shop_order($redirect_to, $action, $post_ids) {
if ($action === 'on-production') {
foreach ($post_ids as $post_id) {
$order = wc_get_order($post_id);
$order->update_status('on-production');
}
}
return $redirect_to;
}