自定义订单状态未显示在客户我的帐户订单历史记录上 [英] Custom order status aren't displayed on the customer my account order history

查看:54
本文介绍了自定义订单状态未显示在客户我的帐户订单历史记录上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WooCommerce 中,我创建了 2 个自定义订单状态.第一个是运输状态",另一个是已批准状态".

In WooCommerce, I have made 2 custom order statuses. The first one is 'shipping status' and the other one is 'approved status'.

在我将一些订单状态更改为这两个新状态(shippingapproved)后,客户无法在其订单历史记录页面上查看此订单.

After I have changed some orders status to these two new statuses (which are shipping or approved), the customer can't view this orders on his order history page.

这是我的代码:

function register_awaiting_shipment_order_status() {


    if('product_manager' == $get_roles || 'administrator' == $get_roles){
        register_post_status( 'wc-shipping', array(
                'label'                     => 'wc-shipping',
                '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'                     => 'wc-approved',
                '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_awaiting_shipment_order_status' );

但是,如果我将订单状态更改回 Woocommerce 的 默认订单状态(例如已完成"),那么客户可以再次在他的订单历史记录中查看它们.

But if I change the order status back to the Woocommerce's default order statuses (for example "completed"), then the customer can view them i his order history again.

我做错了什么?
如何在客户订单历史记录页面上显示具有新自定义状态的新订单?

What I am doing wrong?
How can I display new orders with that new custom statuses on customer order history page?

谢谢.

推荐答案

我已经更正了您代码中的小错误.您需要将 textdomain 替换为您的主题文本域(或 slug).

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

要完成并显示这个新的自定义订单状态,您还需要在 wc_order_statuses 过滤器钩子中注册它们,该钩子用于 my_account/orders.php 模板,用于在客户的帐户页面上显示客户订单.

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.

这是重新访问的代码:

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

此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

代码经过测试且功能齐全.

The code is tested and fully functional.

参考文献:

这篇关于自定义订单状态未显示在客户我的帐户订单历史记录上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆