Custom order status aren't displayed on the customer my account order history

…衆ロ難τιáo~ 提交于 2019-12-06 01:38:55

I have corrected small mistakes in your code. You will need to replace textdomain everywhere by your theme text domain (or slug).

To complete and display this new custom orders status, you need also to register them in wc_order_statuses filter hook that is used on my_account/orders.php template that displays customers orders on their account pages.

This is the revisited code:

function register_new_custom_order_statuses() {

    if('product_manager' == $get_roles || 'administrator' == $get_roles){
        register_post_status( 'wc-shipping', array(
            'label'                     => _x( 'Shipping', 'Order status', 'textdomain' ),
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Shipping <span class="count">(%s)</span>', 'Shipping <span class="count">(%s)</span>' )
        ) );
    }

    if('approver' == $get_roles  || 'administrator' == $get_roles ||'product_manager' == $get_roles ){
        register_post_status( 'wc-approved', array(
            'label'                     => _x( 'Approved', 'Order status', 'textdomain' ),
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Approved <span class="count">(%s)</span>', 'Approved <span class="count">(%s)</span>' )
        ) );
    }
}
add_action( 'init', 'register_new_custom_order_statuses' );

// Register new statuses in wc_order_statuses (function).
function register_new_custom_wc_order_statuses( $order_statuses ) {
    $order_statuses['wc-shipping'] = _x( 'Shipping', 'Order status', 'textdomain' );
    $order_statuses['wc-approved'] = _x( 'Approved', 'Order status', 'textdomain' );
    return $order_statuses;
}
add_filter( 'wc_order_statuses', 'register_new_custom_wc_order_statuses' );

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and fully functional.


References:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!