我按照 THIS 教程更改优惠券字段和按钮文本,在代码片段中使用以下脚本:
/**
* Change the CartFlows Coupon Field text and Button text.
*
* @param array $coupon_field array of field strings/texts.
* @return array
*/
add_filter( 'cartflows_coupon_field_options', 'change_cartFlows_coupon_field_strings', 10, 1 );
function change_cartFlows_coupon_field_strings( $coupon_field ){
$coupon_field = array(
'field_text' => __( 'Coupon Code', 'cartflows' ), // Coupon input field text/placeholder.
'button_text' => __( 'Apply', 'cartflows' ), // Apply coupon button text.
'class' => '', // Coupon input field class.
);
return $coupon_field; // Returning the modified data with new strings.
}
该脚本按预期工作。但是,当点击“有优惠券?”时,优惠券代码是可折叠的。更改标题“有优惠券吗?”对于另一种语言,我尝试使用此代码:
// Attempted script to change the coupon title
function cartFlows_rename_coupon_message_on_checkout() {
return 'Have a Promo Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'cartFlows' ) . '</a>';
}
add_filter( 'cartFlows_checkout_coupon_message', 'cartFlows_rename_coupon_message_on_checkout' );
但是,这个脚本在这种情况下似乎不起作用。我无法确定此问题的原因。下面,我添加了 HTML 片段以供参考:
<div class="wcf-custom-coupon-field wcf-hide-field" id="wcf_custom_coupon_field"><a href="#" id="wcf_optimized_wcf_custom_coupon_field"><div class="dashicons dashicons-arrow-right"></div> Have a coupon?</a>
<div class="wcf-coupon-col-1">
<span>
<input type="text" name="coupon_code" class="input-text wcf-coupon-code-input" placeholder="Coupon code" id="coupon_code" value="">
</span>
</div>
<div class="wcf-coupon-col-2">
<span>
<button type="button" class="button wcf-submit-coupon wcf-btn-small" name="apply_coupon" value="Apply">Apply</button>
</span>
</div>
</div>
CartFlows 中没有“cartFlows_checkout_coupon_message”过滤器。
我认为您打算使用“woocommerce_checkout_coupon_message”过滤器