I have the below code and Its getting the placeholder value from the field key which its defined in the first code. How can I add a different placeholder for each value?
/* new field under Billing */
// Custom function that handle the Custom field settings
function custom_checkout_fields_settings_vat() {
$text_domain = 'toBeTranslatd';
return array(
'vat' => __('VAT', 'toBeTranslatd'),
'phone' => __('Phone Number', 'toBeTranslatd'),
);
}
// Add custom billing fields to Checkout and My account edit addresses
add_filter( 'woocommerce_billing_fields' , 'custom_billing_fields' );
function custom_billing_fields( $fields ) {
$settings = custom_checkout_fields_settings_vat(); // Load settings
// Loop through setting fields
foreach ( $settings as $field_key => $field_label ) {
$fields['billing_'.$field_key] = array(
'type' => 'text',
'label' => $field_label,
'placeholder' => $field_label,
'class' => $field_key === 'vat' ? array('form-field-wide') : array('form-field-wide'),
'required' => $field_key === 'vat' ? false : true,
'clear' => true,
'priority' => $field_key === 'vat' ? 31 : 32,
);
}
return $fields;
}
I changed the placeholder to
'placeholder' => $field_key === 'vat' ? 15 VAT number : 050011223344,
but it broke my website.
CodePudding user response:
Your value should be a string
'placeholder' => $field_key === 'vat' ? '15 VAT number' : '050011223344',