如何更改“有促销代码?”

时间:2017-03-15 22:48:22

标签: wordpress woocommerce wordpress-theming

如何更改woocommerce优惠券中的“拥有促销代码?”标签?

我试过包含一些我在互联网上找到的PHP代码,但它没有用。

请帮助我;我还在form-coupon.php文件中将“有促销代码?”更改为“请在下方输入您的会员代码以应用折扣”。

代码如下:

 if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

if ( ! wc_coupons_enabled() ) {
    return;
}

if ( empty( WC()->cart->applied_coupons ) ) {
    $info_message = apply_filters( 'woocommerce_checkout_coupon_message', __( 'Please enter your membership code in the coupon to apply discount', 'woocommerce' ) . ' <a href="#" class="showcoupon">' . __( 'Please enter your membership code below to apply discount', 'woocommerce' ) . '</a>' );
    wc_print_notice( $info_message, 'notice' );
}
?>

<form class="checkout_coupon" method="post" style="display:none">

    <p class="form-row form-row-first">
        <input type="text" name="coupon_code" class="input-text" placeholder="<?php esc_attr_e( 'Member Code', 'woocommerce' ); ?>" id="coupon_code" value="" />
    </p>

    <p class="form-row form-row-last">
        <input type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply code', 'woocommerce' ); ?>" />
    </p>

    <div class="clear"></div>
</form>

`

由于

1 个答案:

答案 0 :(得分:1)

查看this article并按照说明操作。或者只需将以下代码粘贴到主题函数文件中:

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 ( 'Apply Coupon' === $text ) {
        $translated_text = 'Put your text here';
    }
    return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );

然后更改&#39;将您的文字放在这里&#39;。