【问题标题】:Replace order status names everywhere incl. Woocommerce admin order preview到处替换订单状态名称,包括。 Woocommerce 管理员订单预览
【发布时间】:2023-04-10 04:17:02
【问题描述】:

在每种情况下,我都需要将“暂停”重命名为“待批准”,将“处理中”重命名为“已批准”。 (顺便说一句,我是DIY店主,不是开发者)

这个话题让我达到了 60%,Rename multiple order statuses in Woocommerce 现在需要解决这些位置:

  • admin > 订单,预览弹出窗口(眼睛符号)。
  • 前端 > my-account/orders,状态列。
  • 前端 > my-account/view-order/x,摘要行。

我的代码:

add_filter( 'wc_order_statuses', 'rename_order_statuses', 20, 1 );
function rename_order_statuses( $order_statuses ) {
    $order_statuses['wc-processing'] = _x( 'Approved', 'Order status', 'woocommerce' );
    $order_statuses['wc-on-hold']    = _x( 'Pending Approval', 'Order status', 'woocommerce' );

    return $order_statuses;
}
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 Approved', 'woocommerce' );
    $actions['mark_on-hold']    = __( 'Mark Pending Approval', 'woocommerce' );

    return $actions;
}

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-processing'] ) )
        $views['wc-processing'] = str_replace( 'Processing', __( 'Approved', 'woocommerce'), $views['wc-processing'] );

    if( isset( $views['wc-on-hold'] ) )
        $views['wc-on-hold'] = str_replace( 'On hold', __( 'Pending Approval', 'woocommerce'), $views['wc-on-hold'] );

    return $views;
}

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce orders


    【解决方案1】:

    您由Rename multiple order statuses in Woocommerce 回答代码生成的代码已经涵盖了所有内容(90%),包括:

    前端 > my-account/orders,状态列。

    前端>my-account/view-order/x,摘要行

    否则,如果它不起作用,可能是由您主题的其他自定义、插件或您自己的自定义引起的。


    现在处理Admin >订单,预览弹出窗口(眼睛符号)使用以下代码:

    add_filter( 'woocommerce_admin_order_preview_actions', 'filter_admin_order_preview_actions', 10, 2 );
    function filter_admin_order_preview_actions( $actions, $order ) {
        $actions        = array();
        $status_actions = array();
    
        if ( $order->has_status( array( 'pending' ) ) ) {
            $status_actions['on-hold'] = array(
                'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=on-hold&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
                'name'   => __( 'On-hold', 'woocommerce' ),
                'title'  => __( 'Change order status to on-hold', 'woocommerce' ),
                'action' => 'on-hold',
            );
        }
        if ( $order->has_status( array( 'pending', 'on-hold' ) ) ) {
            $status_actions['processing'] = array(
                'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
                'name'   => __( 'Approved', 'woocommerce' ),
                'title'  => __( 'Change order status to approved', 'woocommerce' ),
                'action' => 'processing',
            );
        }
    
        if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
            $status_actions['complete'] = array(
                'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
                'name'   => __( 'Completed', 'woocommerce' ),
                'title'  => __( 'Change order status to completed', 'woocommerce' ),
                'action' => 'complete',
            );
        }
    
        if ( $status_actions ) {
            $actions['status'] = array(
                'group'   => __( 'Change status: ', 'woocommerce' ),
                'actions' => $status_actions,
            );
        }
        return $actions;
    }
    

    并在悬停时重命名管理订单列表按钮上的状态:

    add_filter( 'woocommerce_admin_order_actions', 'rename_admin_order_status_action_button', 10, 2 );
    function rename_admin_order_status_action_button( $actions, $order ) {
        // Display the button for all orders that have a 'processing', 'pending' or 'on-hold' status
        if ( isset($actions['processing']) ) {
            $actions['processing']['name'] = __( 'Approved', 'woocommerce');
        }
    
        return $actions;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

    • 感谢 Loic 提供新代码,并证明我的代码在前端工作。不幸的是,我不能产生相同的结果。一个一个地禁用每个插件和自定义。运行 StoreFront 主题。最新的主题、Woo 和 Wordpress。唯一过时的组件是此服务器上的 PHP 5.6。这和它有什么关系吗?
    • @Scott 为了测试,我使用和你一样的东西:Storefront + Woocommerce 3.5.4 (Php 版本在这里无效)。您的第一个功能代码在前端重命名相关订单状态。因此,在您的情况下还有其他一些交互作用...检查模板是否在后端 > Woocommerce > 状态 中是最新的(在页面末尾:“模板覆盖”)
    • 再次感谢。我终于意识到了这个问题......这次我使用的是 PHP sn-ps 插件而不是子主题,并且我将 sn-p 设置为仅在管理员中运行。改成到处跑,问题解决了!菜鸟失误。现在唯一显示原始名称的地方是当鼠标悬停在 Admin>Orders 列表中的状态时。但我可以忍受。
    • @Scott 你说 “现在唯一显示原始名称的地方是当悬停在 Admin>Orders list 中的状态时...” 我添加了一些代码来处理这个问题也……检查一下。
    猜你喜欢
    • 2019-08-29
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    相关资源
    最近更新 更多