这是我不知道的挑战。我几乎在其他任何地方都将“优惠券”重命名为“促销”。但是,重命名调用优惠券和标签的WC LABEL要困难得多。
以下是我所讲的屏幕截图:
我已经在整个网站范围内将“优惠券”的所有使用重命名为“促销”。这使我的头发掉下来。有没有人成功改变过这个?我想念什么?
// 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 );
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 );
答案 0 :(得分:0)
// Hide 'Coupon: CODE' in cart totals and instead return generic 'Promo Code Applied'
add_filter( 'woocommerce_cart_totals_coupon_label', 'woocommerce_change_coupon_label' );
function woocommerce_change_coupon_label() {
echo 'Promo Code Applied';
}
答案 1 :(得分:0)
add_filter( 'woocommerce_cart_totals_coupon_label', 'woocommerce_change_coupon_label' );
function woocommerce_change_coupon_label($sprintf, $coupon) {
return 'Promo ' . $coupon->code;
}
答案 2 :(得分:0)
我找到了满足所有需求的解决方案。
function woocommerce_change_coupon_label($coupon)
{
$coupon_code = substr($coupon, strpos($coupon, ': ') + 1);
return 'Custom text: '.$coupon_code;
}
add_filter('woocommerce_cart_totals_coupon_label', 'woocommerce_change_coupon_label');
首先我们使用函数“substr”获取优惠券代码,然后在“return”处的优惠券代码前面插入所需的文本。