我已经通过WooCommerce设置更新了购物篮字段的占位符,如下所示:
但是在前端,以前的占位符仍然存在:
我还使用了以下代码,该代码是从另一个StackOverflow线程改编而成的,该线程旨在覆盖占位符内容,但默认设置仍然存在。
add_filter('woocommerce_default_address_fields', 'override_default_address_checkout_fields', 20, 1);
function override_default_address_checkout_fields( $address_fields ) {
$address_fields['state']['placeholder'] = 'State';
$address_fields['postcode']['placeholder'] = 'Postcode';
return $address_fields;
}
请告知我如何获得所需的占位符文本!
答案 0 :(得分:1)
在woocommerce默认情况下,没有您所描述的设置。因此,您正在使用第三方插件来自定义字段。因此,您需要尝试具有更高挂接优先级的多种方法。
所以一一尝试:
1)使用woocommerce_default_address_fields过滤器挂钩(具有更高优先级的挂钩):
add_filter('woocommerce_default_address_fields', 'customize_default_address_fields', 10000, 1 );
function customize_default_address_fields( $address_fields ) {
$address_fields['state']['placeholder'] = __('State', 'woocommerce');
$address_fields['postcode']['placeholder'] = __('Postcode', 'woocommerce');
return $address_fields;
}
2)使用woocommerce_checkout_fields
过滤器挂钩:
add_filter('woocommerce_checkout_fields', 'customize_checkout_fields', 10000, 1 );
function customize_checkout_fields( $fields ) {
$fields['billing']['billing_state']['placeholder'] = __('State', 'woocommerce');
$fields['shipping']['shipping_state']['placeholder'] = __('State', 'woocommerce');
$fields['billing']['billing_postcode']['placeholder'] = __('Postcode', 'woocommerce');
$fields['shipping']['shipping_postcode']['placeholder'] = __('Postcode', 'woocommerce');
return $fields;
}
3)使用woocommerce_billing_fields
和woocommerce_shipping_fields
过滤钩子:
add_filter('woocommerce_billing_fields', 'customize_billing_fields', 10000, 1 );
function customize_billing_fields( $billing_fields ) {
$billing_fields['billing_state']['placeholder'] = __('State', 'woocommerce');
$billing_fields['billing_postcode']['placeholder'] = __('Postcode', 'woocommerce');
return $billing_fields;
}
add_filter('woocommerce_shipping_fields', 'customize_shipping_fields', 10000, 1 );
function customize_shipping_fields( $shipping_fields ) {
$shipping_fields['shipping_state']['placeholder'] = __('State', 'woocommerce');
$shipping_fields['shipping_postcode']['placeholder'] = __('Postcode', 'woocommerce');
return $shipping_fields;
}
所有代码都放在活动子主题(或活动主题)的function.php文件中。
我希望其中之一能起作用。没有第三方插件,这些代码中的每一个都可以完美地工作。