更改 WooCommerce 结帐国家字段默认选项显示标签
Change WooCommerce checkout country field default option displayed label
如何编辑现有数组的默认值 - 已设法使用此编辑标签但无法使用此选项 属性 工作:
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_country']['options value="default"'] = 'My new select prompt';
$fields['billing']['billing_country']['label'] = 'Are you purchasing as a Company Y/N or from the UK?';
return $fields;
}
要更改 WooCommerce 国家字段默认选项在结帐页面中显示的值,您可以这样使用以下复合挂钩:
add_filter( 'woocommerce_form_field_country', 'filter_form_field_country', 10, 4 );
function filter_form_field_country( $field, $key, $args, $value ) {
// Only in checkout page for "billing" city field
if ( is_checkout() && 'billing_country' === $key ) {
$search = esc_html__( 'Select a country / region…', 'woocommerce' ); // String to search
$replace = esc_html__( 'My new select prompt', 'woocommerce' ); // Replacement string
$field = str_replace( $search, $replace, $field );
}
return $field;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
那么你可以继续你的问题代码如下:
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_country']['label'] = __('Are you purchasing as a Company Y/N or from the UK?', 'woocommerce');
return $fields;
}
如何编辑现有数组的默认值 - 已设法使用此编辑标签但无法使用此选项 属性 工作:
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_country']['options value="default"'] = 'My new select prompt';
$fields['billing']['billing_country']['label'] = 'Are you purchasing as a Company Y/N or from the UK?';
return $fields;
}
要更改 WooCommerce 国家字段默认选项在结帐页面中显示的值,您可以这样使用以下复合挂钩:
add_filter( 'woocommerce_form_field_country', 'filter_form_field_country', 10, 4 );
function filter_form_field_country( $field, $key, $args, $value ) {
// Only in checkout page for "billing" city field
if ( is_checkout() && 'billing_country' === $key ) {
$search = esc_html__( 'Select a country / region…', 'woocommerce' ); // String to search
$replace = esc_html__( 'My new select prompt', 'woocommerce' ); // Replacement string
$field = str_replace( $search, $replace, $field );
}
return $field;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。
那么你可以继续你的问题代码如下:
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_country']['label'] = __('Are you purchasing as a Company Y/N or from the UK?', 'woocommerce');
return $fields;
}