在 Woocommerce 中重命名多个订单状态

Rename multiple order statuses in Woocommerce(在 Woocommerce 中重命名多个订单状态)
本文介绍了在 Woocommerce 中重命名多个订单状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试通过编辑我的主题的 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 中重命名多个订单状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)