我试图更改"结算地址2"的字段占位符在结帐页面中,使用以下代码:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields',9999 );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_address_2']['placeholder']="dssfsd";
return $fields;
}
它只会改变一段时间而不是返回它的默认值。 请参阅以下视频(10s): https://www.youtube.com/watch?v=-qOZ67gFQ98
答案 0 :(得分:2)
获得此功能的唯一方法是使用woocommerce_default_address_fields
,但它会更改地址2结帐字段的结算和发货占位符:
add_filter( 'woocommerce_default_address_fields', 'custom_override_default_checkout_fields', 10, 1 );
function custom_override_default_checkout_fields( $address_fields ) {
$address_fields['address_2']['placeholder'] = __( 'dssfsd', 'woocommerce' );
return $address_fields;
}
代码进入活动子主题(或活动主题)的function.php文件。
经过测试和工作
现在,如果您想更改仅地址2 结算字段占位符,您将:
以下是两个挂钩函数的代码:
add_filter( 'woocommerce_default_address_fields', 'custom_override_default_checkout_fields', 10, 1 );
function custom_override_default_checkout_fields( $address_fields ) {
// Remove labels for "address 2" shipping fields
unset($address_fields['address_2']['placeholder']);
return $address_fields;
}
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields', 90, 1 );
function custom_override_checkout_fields( $fields ) {
// Add custom billing "address 2" label
$fields['billing']['billing_address_2']['placeholder'] = __( 'dssfsd', 'woocommerce' );
// Put back shipping "address 2" label
$fields['shipping']['shipping_address_2']['placeholder'] = __( 'Apartment, suite, unit etc. (optional)', 'woocommerce' );
return $fields;
}
代码进入活动子主题(或活动主题)的function.php文件。
经过测试和工作