WooCommerce管理员订单页面更改折扣标签

时间:2020-06-02 16:16:13

标签: php wordpress woocommerce gettext orders

在WooCommerce的最新更新中,他们将折扣改为优惠券。这在订单总数表中。请参阅此屏幕截图,以了解>清晰https://prnt.sc/sq6xfh

我想尽可能将其更改为“折扣”,因为在您实际应用折扣后说“优惠券”并没有多大意义。理想情况下,最好在需要时显示“折扣”和“优惠券”行,因为有时您可以应用优惠券和折扣。

就目前而言,我正在尝试更改屏幕快照中上面指出的Discount(s)标签。

我已经在插件核心文件中找到了代码,并且知道我无法更改,这是代码:

    </tr>
    <?php if ( 0 < $order->get_total_discount() ) : ?>
        <tr>
            <td class="label"><?php esc_html_e( 'Coupon(s):', 'woocommerce' ); ?></td>
            <td width="1%"></td>
            <td class="total">-
                <?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
            </td>
        </tr>
    <?php endif; ?>

我不确定如何通过我的functions.php将上面代码中的Coupon(s)更改为Discounts

任何帮助表示赞赏。 干杯 尼克

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式使用WordPress gettext钩子:

add_filter('gettext', 'custom_strings_translation', 20, 3);
function custom_strings_translation( $translated_text, $text, $domain ) {
global $pagenow, $typenow;

    // Settings
    $current_text = "Coupon(s):";
    $new_text     = "Discount(s):";

    // Targeting admin single order pages
    if( is_admin() && in_array($pagenow, ['post.php', 'post-new.php']) && 'shop_order' === $typenow && $current_text === $text ){
        $translated_text =  __( $new_text, $domain );
    }
    return $translated_text;
}

代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。

相关答案: