我正在尝试通过编辑我的主题的 functions.php 文件来重命名多个 WooCommerce 订单状态.几年前我发现这里发布的一些代码可以更改单个订单状态,但是由于我对 php 非常缺乏经验,我不知道如何扩展它以更改多个状态.理想情况下,我还想将wc-processing"重命名为Paid",将wc-on-hold"重命名为Pending".
这是我找到的用于编辑单个订单状态的代码:
function wc_renaming_order_status( $order_statuses ) {foreach ( $order_statuses as $key => $status ) {$new_order_statuses[ $key ] = $status;if ('wc-completed' === $key ) {$order_statuses['wc-completed'] = _x('订单已收到', '订单状态', 'woocommerce');}}返回 $order_statuses;}add_filter('wc_order_statuses', 'wc_renaming_order_status');有人知道我需要进行哪些更改才能更改其他状态吗?
由于存在 Pending 订单状态,您还需要将现有的Pending"重新命名为Pending"地位.如果不是,您将获得 2 个具有相同待定"的不同状态.标签.
首先重命名这些订单状态:
add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );函数 rename_order_statuses( $order_statuses ) {$order_statuses['wc-completed'] = _x('订单已收到', '订单状态', 'woocommerce');$order_statuses['wc-processing'] = _x('付费','订单状态','woocommerce');$order_statuses['wc-on-hold'] = _x('Pending', 'Order status', 'woocommerce');$order_statuses['wc-pending'] = _x('等待','订单状态','woocommerce');返回 $order_statuses;}也在批量编辑订单列表下拉菜单中:
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );函数 custom_dropdown_bulk_actions_shop_order( $actions ) {$actions['mark_processing'] = __( 'Markpaid', 'woocommerce');$actions['mark_on-hold'] = __( 'Mark pending', 'woocommerce' );$actions['mark_completed'] = __( 'Mark order received', 'woocommerce' );返回 $actions;}这也是需要的(对于顶部菜单):
foreach( array( 'post', 'shop_order' ) as $hook )add_filter( "views_edit-$hook", 'shop_order_modified_views');功能 shop_order_modified_views( $views ){if( isset( $views['wc-completed'] ) )$views['wc-completed'] = str_replace('Completed', __('Order Received', 'woocommerce'), $views['wc-completed'] );if( isset( $views['wc-processing'] ) )$views['wc-processing'] = str_replace('Processing', __('Paid', 'woocommerce'), $views['wc-processing'] );if( isset( $views['wc-on-hold'] ) )$views['wc-on-hold'] = str_replace('On hold', __('Pending', 'woocommerce'), $views['wc-on-hold'] );if( isset( $views['wc-pending'] ) )$views['wc-pending'] = str_replace('Pending', __('Stucked', 'woocommerce'), $views['wc-pending'] );返回 $views;}(感谢
代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.
<块引用>从 Woocommerce 3.3 开始处理管理订单列表中的预览弹出窗口(眼睛符号):
随处替换订单状态名称包括Woocommerce 管理员订单预览
I'm trying to rename multiple WooCommerce order status by editing my theme's functions.php file. I found some code posted here a couple years ago that works to change a single order status, but since I'm very inexperienced with php, I don't know how to expand on it to change multiple statuses. Ideally I'd also like to rename 'wc-processing' to 'Paid' and 'wc-on-hold' to 'Pending'.
Here's the code I found to edit a single order status:
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-completed' === $key ) {
$order_statuses['wc-completed'] = _x( 'Order Received', 'Order status', 'woocommerce' );
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
Anyone know what changes I need to make to change additional statuses?
As Pending order status exist, you need also to rename the existing "Pending" status. If not you will get 2 different statuses with the same "Pending" label.
First to rename those order statuses:
add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );
function rename_order_statuses( $order_statuses ) {
$order_statuses['wc-completed'] = _x( 'Order Received', 'Order status', 'woocommerce' );
$order_statuses['wc-processing'] = _x( 'Paid', 'Order status', 'woocommerce' );
$order_statuses['wc-on-hold'] = _x( 'Pending', 'Order status', 'woocommerce' );
$order_statuses['wc-pending'] = _x( 'Waiting', 'Order status', 'woocommerce' );
return $order_statuses;
}
And Also in the bulk edit order list dropdown:
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
$actions['mark_processing'] = __( 'Mark paid', 'woocommerce' );
$actions['mark_on-hold'] = __( 'Mark pending', 'woocommerce' );
$actions['mark_completed'] = __( 'Mark order received', 'woocommerce' );
return $actions;
}
And also this is needed (for the top menu):
foreach( array( 'post', 'shop_order' ) as $hook )
add_filter( "views_edit-$hook", 'shop_order_modified_views' );
function shop_order_modified_views( $views ){
if( isset( $views['wc-completed'] ) )
$views['wc-completed'] = str_replace( 'Completed', __( 'Order Received', 'woocommerce'), $views['wc-completed'] );
if( isset( $views['wc-processing'] ) )
$views['wc-processing'] = str_replace( 'Processing', __( 'Paid', 'woocommerce'), $views['wc-processing'] );
if( isset( $views['wc-on-hold'] ) )
$views['wc-on-hold'] = str_replace( 'On hold', __( 'Pending', 'woocommerce'), $views['wc-on-hold'] );
if( isset( $views['wc-pending'] ) )
$views['wc-pending'] = str_replace( 'Pending', __( 'Stucked', 'woocommerce'), $views['wc-pending'] );
return $views;
}
(Thanks to brasofilo : Change WP admin post status filter for custom post type)
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Since Woocommerce 3.3 to handle the preview popup (eye symbol) in admin order list:
Replace order status names everywhere incl. Woocommerce admin order preview
这篇关于在 Woocommerce 中重命名多个订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
以编程方式将可下载文件添加到 Woocommerce 产品Add programmatically a downloadable file to Woocommerce products(以编程方式将可下载文件添加到 Woocommerce 产品)
获取今天 Woocommerce 中每种产品的总订单数Get today#39;s total orders count for each product in Woocommerce(获取今天 Woocommerce 中每种产品的总订单数)
在 WooCommerce 和电话字段验证问题中添加自定义注Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和电话字段验证问题中添加自定义注册字段
在 Woocommerce 简单产品中添加一个将更改价格的选Add a select field that will change price in Woocommerce simple products(在 Woocommerce 简单产品中添加一个将更改价格的选择字段)
在 WooCommerce 3 中将自定义列添加到管理产品列表Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中将自定义列添加到管理产品列表)
自定义结帐“下订单"按钮输出htmlCustomizing checkout quot;Place Orderquot; button output html(自定义结帐“下订单按钮输出html)