Woocommerce 购物车优惠券价值占位符更改

Woocommerce Cart Coupon Value Placeholder Change

所以,我想我可以通过尝试应用

来改变这一点
input#coupon_code.input-value::placeholder {
content: 'Enter Code here'; }

这是 CSS 但它不起作用,所以我开始寻找它在 php 的

上的位置

我设置了 wordpress,所以我继续 cart.phpcoupon.php

完全不习惯php的环境,浏览了30分钟看到%$符号就头晕

我目前只是想知道如何更改此占位符文本,但无法做到。

谢谢

让我们说 coupon.php 你有以下内容:

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

更改placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>"

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

您在此处看到您的占位符文本的地方,就是您更改它的地方。

在 WooCommerce 或与此相关的任何插件中更改文本的首选方法是使用 gettext 过滤器。最好使用过滤器而不是编辑模板,因为更新 WooCommerce 时可以更改模板。将以下代码放入您的 functions.php 文件中以获得更适合未来的解决方案。

function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Coupon code' :
            $translated_text = __( 'My New Coupon Code Text', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );