Display orders with custom statuses in account page my-account/orders/

Question

I am using code to add my own order status. I can see it on the product edit page, but if I save this status, I cannot see the order with this status in the order list and on my account page. How to make it so that you can see any orders in your personal account, with any custom statuses added using the code.

    // Register new status
function register_awaiting_shipment_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 (%s)', 'Awaiting shipment (%s)' )
    ) );
}
add_action( 'init', 'register_awaiting_shipment_order_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-awaiting-shipment'] = 'Awaiting shipment';
        }
    }
 
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

Theme and plugin conflicts are excluded. Plugin WooCommerce Order Status & Actions Manager does a good job and does not have the flaws that my code has, but I want to solve the problem without a plugin using code.

0
WPTricks 2 months 0 Answers 21 views 0

Leave an answer