skip to Main Content

I’ve used the following code to add a couple new order statuses to WooCommerce:

// Register new status
function register_woocommerce_status() {
    register_post_status( 'wc-ready-for-pickup', array(
        'label'                     => 'Ready for Pickup',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Ready for Pickup (%s)', 'Ready for Pickup (%s)' )
    ) );

    register_post_status( 'wc-ready-for-delivery', array(
        'label'                     => 'Ready for Delivery',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Ready for Delivery (%s)', 'Ready for Delivery (%s)'     )
    ) );
}
add_action( 'init', 'register_woocommerce_status' );    

// Add to list of WC Order statuses
function add_awaiting_shipment_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-ready-for-pickup'] = 'Ready for Pickup';
            $new_order_statuses['wc-ready-for-delivery'] = 'Ready for Delivery';
        }
    }

    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

This all works great for “Ready for Pickup”, but if I try to set the order status to “Ready for Delivery” it just simply won’t reset. It adds to the order notes saying that it did so, but it doesn’t actually set it.

Any ideas what the issue is?

2

Answers


  1. Chosen as BEST ANSWER

    Well, in case anyone else runs into this, here's what ended up working for me:

    I tried various things suggested by others, such as putting wc-ready-for-delivery first instead of wc-ready-for-pickup, removing wc-ready-for-pickup altogether, etc. No matter what I did, the system would just not set it "Ready for Delivery"

    Then I tried changing the key from wc-ready-for-delivery to wc-readyfor-delivery and it works just fine. I have no clue what the issue was, but there you go.


  2. Your issue is that WP limits a status name to 20 characters, and you are at 21 with "wc-ready-for-delivery"

    https://developer.wordpress.org/reference/functions/register_post_status/#user-contributed-notes

    I had a similar problem, thinking it was a permissions issue, but actually it was this 20 character limit.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search