xxxxxxxxxx
add_action( 'handle_bulk_actions-edit-shop_order', 'misha_bulk_process_custom_status', 20, 3 );
function misha_bulk_process_custom_status( $redirect, $doaction, $object_ids ) {
if( 'mark_awaiting_shipping' === $doaction ) {
// change status of every selected order
foreach ( $object_ids as $order_id ) {
$order = wc_get_order( $order_id );
$order->update_status( 'wc-misha-shipping' );
}
// do not forget to add query args to URL because we will show notices later
$redirect = add_query_arg(
array(
'bulk_action' => 'marked_awaiting_shipping',
'changed' => count( $object_ids ),
),
$redirect
);
}
return $redirect;
}
xxxxxxxxxx
add_filter( 'bulk_actions-edit-shop_order', 'misha_register_bulk_action' ); // edit-shop_order is the screen ID of the orders page
function misha_register_bulk_action( $bulk_actions ) {
$bulk_actions[ 'mark_awaiting_shipping' ] = 'Change status to awaiting shipping'; // <option value="mark_awaiting_shipping">Change status to awaiting shipping</option>
return $bulk_actions;
}