简体   繁体   中英

Woocommerce Custom Order Status Does Not Show

I have been trying to add custom order status Shipped in woocommerce.

here is the code

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') );

The Shipping status is shown everywhere in woocommerce and it is working perfectly

在此处输入图像描述

Whenever i change the status of an order to shipped the order is updated successfully

Now the problem is that shipped orders are not showing in orders table

在此处输入图像描述

The following works to add a functional custom order status in a custom plugin:

// 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 custom order status after processing
    foreach ($actions as $key => $action) {
        $new_actions[$key] = $action;
        if ('mark_processing' === $key) {
            $new_actions['mark_order-shipped'] = __( 'Mark Shipped', 'woocommerce' );
        }
    }

    return $new_actions;
}

add_action( 'init', 'register_shipped_status' );
add_filter( 'wc_order_statuses', 'add_awaiting_shippped_to_order_statuses' );
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

Or for plugins with a Class (and a constructor), remove:

add_action( 'init', 'register_shipped_status' );
add_filter( 'wc_order_statuses', 'add_awaiting_shippped_to_order_statuses' );
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );

And add to the constructor the following:

add_action( 'init', array($this, 'register_shipped_status') );
add_filter( 'wc_order_statuses', array($this, 'add_awaiting_shippped_to_order_statuses') );
add_filter( 'bulk_actions-edit-shop_order', array($this, 'custom_dropdown_bulk_actions_shop_order'), 20, 1 );

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM