Halloween Sale 15% off Ends in See the plans
PHP

Add an "Awaiting Shipment" Order Status

Registers a new order status you can set on orders that are packed and waiting for the carrier, and adds it to the bulk actions menu.

Don’t have WPIDE yet? Install it on your site

Code

add_filter( 'woocommerce_register_shop_order_post_statuses', function ( $statuses ) {
    $statuses['wc-awaiting-shipment'] = array(
        'label'                     => 'Awaiting shipment',
        'public'                    => false,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        /* translators: %s: number of orders */
        'label_count'               => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' ),
    );

    return $statuses;
} );

add_filter( 'wc_order_statuses', function ( $statuses ) {
    $new = array();

    foreach ( $statuses as $key => $label ) {
        $new[ $key ] = $label;

        if ( 'wc-processing' === $key ) {
            $new['wc-awaiting-shipment'] = 'Awaiting shipment';
        }
    }

    return $new;
} );

$wpide_awaiting_bulk = function ( $actions ) {
    $actions['mark_awaiting-shipment'] = 'Change status to awaiting shipment';

    return $actions;
};

add_filter( 'bulk_actions-woocommerce_page_wc-orders', $wpide_awaiting_bulk, 20 );
add_filter( 'bulk_actions-edit-shop_order', $wpide_awaiting_bulk, 20 );

add_filter( 'woocommerce_reports_order_statuses', function ( $statuses ) {
    if ( is_array( $statuses ) ) {
        $statuses[] = 'awaiting-shipment';
    }

    return $statuses;
} );

Notes

Change the slug and label to create a different status. Orders keep this status if you later remove the snippet, so move them to another status first.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.