不能更改购物车总数中的WooCommerce优惠券标签 [英] Can't Change WooCommerce Coupon Label In Cart Totals
本文介绍了不能更改购物车总数中的WooCommerce优惠券标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
事实证明,这是一个我无法理解的挑战。几乎在其他任何地方,我都会处理将"优惠券"更名为"促销"的问题。然而,使用优惠券名称和标签的WC标签的重命名要困难得多。
下面是我所说的截图:
我几乎把"优惠券"的所有用法都改成了"促销"。这件衣服让我头发都掉光了。有没有人成功地改变过这一点?我错过了什么?
将下面的"优惠券"代码重命名为"促销"代码
// rename the coupon field on the cart page
function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
if ( 'Coupon code:' === $text ) {
$translated_text = 'Promo Code:';
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );
// rename the "Have a Coupon?" message on the checkout page
function woocommerce_rename_coupon_message_on_checkout() {
return 'Have a Customer Code?' . ' <a href="#" class="showcoupon">' . __(
'Click here to enter your code', 'woocommerce' ) . '</a>';
}
add_filter( 'woocommerce_checkout_coupon_message',
'woocommerce_rename_coupon_message_on_checkout' );
// rename the coupon field on the checkout page
function woocommerce_rename_coupon_field_on_checkout( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
if ( 'Coupon code' === $text ) {
$translated_text = 'Promo Code';
} elseif ( 'Apply coupon' === $text ) {
$translated_text = 'Apply Code';
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_checkout', 10, 3 );
下面的WC优惠券通知/消息代码
function woocommerce_coupon_message( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Coupon' :
$translated_text = __( 'Promo', 'woocommerce' );
break;
case 'promo' :
$translated_text = __( 'promo', 'woocommerce' );
break;
case 'Please enter a coupon code.' :
$translated_text = __( 'Please enter a Promo code.', 'woocommerce' );
break;
case 'Coupon code already applied!' :
$translated_text = __( 'Promo code already applied!', 'woocommerce' );
break;
case 'Coupon has been removed.' :
$translated_text = __( 'Promo has been removed', 'woocommerce' );
break;
case 'Coupon code applied successfully.' :
$translated_text = __( 'Promo code applied successfully.', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_coupon_message', 20, 3 );
推荐答案
add_filter( 'woocommerce_cart_totals_coupon_label', 'woocommerce_change_coupon_label' );
function woocommerce_change_coupon_label($sprintf, $coupon) {
return 'Promo ' . $coupon->code;
}
这篇关于不能更改购物车总数中的WooCommerce优惠券标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文