如何添加woocommerce自定义订单状态? [英] How to add woocommerce custom order status?

查看:130
本文介绍了如何添加woocommerce自定义订单状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用以下功能向woocommerce添加了新的自定义订单状态.

I have added new custom order status to woocommerce by using following function.

// Register New Order Statuses
function wpex_wc_register_post_statuses() {
	register_post_status( 'wc-custom-order-status', array(
		'label'						=> _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' ),
		'public'					=> true,
		'exclude_from_search'		=> false,
		'show_in_admin_all_list'	=> true,
		'show_in_admin_status_list'	=> true,
		'label_count'				=> _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
	) );
}
add_filter( 'init', 'wpex_wc_register_post_statuses' );

// Add New Order Statuses to WooCommerce
function wpex_wc_add_order_statuses( $order_statuses ) {
	$order_statuses['wc-custom-order-status'] = _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' );
	return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wpex_wc_add_order_statuses' );

无论何时我去编辑订单并将订单状态更改为新添加的自定义订单状态,然后单击保存订单"按钮.加载后,订单状态会自动更改为待处理订单",而不是新添加的自定义订单...

whenever I go to edit order and changed the order status to newly added custom order status and click on Save Order button. After loading the order status automatically changes to Pending Order not stands in newly added custom order...

如何克服这个问题...?

How to overcome this problem...?

推荐答案

您正在注册wc-custom-order-status的订单状态太长-22个字符.这样只会保存帖子状态的前20个字符,这使其无效并引起您的问题.

The order status that you're registering wc-custom-order-status is too long - 22 characters. This results in saving only the first 20 characters of the post status, which makes it invalid and causes your issue.

订单状态被注册为发布状态,发布状态的限制为20个字符.

The order statuses are registered as post statuses, and post statuses have a limitation of 20 characters.

我建议您将您的wc-custom-order-status状态名称更新为wc-shipping-progress,该名称的长度恰好为20个字符.

I suggest that you update your wc-custom-order-status status name to wc-shipping-progress, which is exactly 20 characters in length.

我还发布了代码的更新版本,仅供参考(我仅更改了状态名称):

I'm also posting the updated version of your code, just for reference (I've only changed the status name):

// Register New Order Statuses
function wpex_wc_register_post_statuses() {
    register_post_status( 'wc-shipping-progress', array(
        'label'                     => _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
    ) );
}
add_filter( 'init', 'wpex_wc_register_post_statuses' );

// Add New Order Statuses to WooCommerce
function wpex_wc_add_order_statuses( $order_statuses ) {
    $order_statuses['wc-shipping-progress'] = _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' );
    return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wpex_wc_add_order_statuses' );

这篇关于如何添加woocommerce自定义订单状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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