在最近對 WooCommerce 的更新中,他們將折扣一詞更改為優惠券。這是在訂單總表中。請參閱此屏幕截圖以獲得 > 清晰度https://prnt.sc/sq6xfh我想盡可能將其改回折扣,因為當您實際應用折扣時說優惠券真的沒有意義。理想情況下,如果需要,最好顯示折扣和優惠券行,因為有時您可能會應用優惠券和折扣?,F在,我正在嘗試更改上面屏幕截圖中指出的折扣標簽。我在插件核心文件中找到了代碼并且知道我無法更改它,這是代碼: </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 回答

MMMHUHU
TA貢獻1834條經驗 獲得超8個贊
gettext您可以這樣使用 WordPress掛鉤:
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 文件。測試和工作。
- 1 回答
- 0 關注
- 195 瀏覽
添加回答
舉報
0/150
提交
取消