【问题标题】:Replace heading texts on admin single Order pages only in WooCommerce仅在 WooCommerce 中替换管理单订单页面上的标题文本
【发布时间】:2019-05-30 02:29:51
【问题描述】:

我正在尝试在我的管理面板中的“订单详情”页面中修改 BillingShipping 文本。 (Screenshot)

我知道,我可以通过编辑以下目录中的“class-wc-meta-box-order-data.php”文件来实现这一点,我成功了,但我知道我的更改将在更新后消失。

文件位置:
wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-data.php

账单文本位于 312 行,运输文本位于 428 行。

我想用发件人信息

替换帐单

运费将替换为收件人信息

我尝试使用以下代码并且它有效,但我只想在管理面板中的“订单详细信息”页面上替换这些词,但此代码也在前端替换这些词&我只是想要在管理面板中更新这些单词。

add_filter('gettext', 'translate_reply');
add_filter('ngettext', 'translate_reply');

function translate_reply($translated) {
$translated = str_ireplace('Shipping', 'Recipient Information', 
$translated);
$translated = str_ireplace('Billing', 'Sender Information', $translated);
return $translated;
}

我也尝试将文件目录放在我的子主题中(编辑后),但没有成功。

【问题讨论】:

    标签: php wordpress woocommerce gettext orders


    【解决方案1】:

    以下内容仅针对管理员单个“编辑”(和“新建”)订单页面:

    add_filter(  'gettext',  'change_admin_single_order_heading3', 10, 3 );
    add_filter(  'ngettext',  'change_admin_single_order_heading3', 10, 3 );
    function change_admin_single_order_heading3( $translated, $text, $domain  ) {
        global $pagenow;
    
        if ( is_admin() && ( ( $pagenow === 'post.php' && isset($_GET['post']) && get_post_type($_GET['post']) === 'shop_order' )
        || ( $pagenow === 'post-new.php' && isset($_GET['post-type']) && $_GET['post-type'] === 'shop_order' ) ) ) {
    
            if( $text === 'Billing' && $domain === 'woocommerce' ){
                $translated = esc_html__( 'Sender Information', $domain );
            }
    
            if( $text === 'Shipping' && $domain === 'woocommerce' ){
                $translated = esc_html__( 'Recipient Information', $domain );
            }
    
            // Addition asked in your comment
            if( $text === 'Shipping:' && $domain === 'woocommerce' ){
                $translated = esc_html__( 'Some text', $domain );
            }
        }
        return $translated;
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      • 2015-03-19
      相关资源
      最近更新 更多