Adding multiple custom order statuses in Woocommerce

The following code, will add “Awaiting shipment” and “Verification” custom order statuses and it will replace the code from your question:

Code goes in function.php file of your active child theme (active theme). Tested and works.

add_action( 'init', 'register_custom_statuses_as_order_status' );
function register_custom_statuses_as_order_status() {

    register_post_status( 'wc-awaiting-shipment', array(
        'label'                     => __('Awaiting shipment'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Awaiting shipment <span class="count">(%s)</span>', 'Awaiting shipment <span class="count">(%s)</span>' )
    ) );

    register_post_status( 'wc-verification', array(
        'label'                     => __('Verification'),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Verification <span class="count">(%s)</span>', 'Verification <span class="count">(%s)</span>' )
    ) );
}

// Add to list of WC Order statuses
add_filter( 'wc_order_statuses', 'add_additional_custom_statuses_to_order_statuses' );
function add_additional_custom_statuses_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-awaiting-shipment'] = __('Awaiting shipment');
            $new_order_statuses['wc-verification'] = __('Verification');
        }
    }
    return $new_order_statuses;
}

Nguồn : Sưu tập

Đánh giá post
[related_posts_by_tax posts_per_page="6" title="Bài liên quan" taxonomies="category,post_tag"]

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Hotline: 0974.0707.83(Zalo/Viber)