Hi to all in my plugin I added custom fields to WooCommerce checkout:
add_action('woocommerce_checkout_fields', 'my_custom_billing_fields', 10, 1);
function my_custom_billing_fields($fields) {
$fields['billing']['billing_checkbox'] = array(
'type' => 'checkbox',
'label' => __('I would like to receive an invoice', 'myplugin'),
'class' => array('form-row-wide', 'my_custom_billing_cb'),
'priority' => 25,
'clear' => true
);
$fields['billing']['billing_fiscalcode'] = array(
'type' => 'text',
'placeholder' => __('Codice fiscale', 'myplugin'),
'label' => __('Codice fiscale', 'myplugin'),
'class' => array('form-row-wide', 'inv_create_elecinvoice'),
'priority' => 30,
'clear' => true
);
$fields['billing']['billing_vatcode'] = array(
'type' => 'text',
'placeholder' => __('Partita Iva / VAT', 'myplugin'),
'label' => __('Partita Iva / VAT', 'myplugin'),
'class' => array('form-row-wide'),
'priority' => 31,
'clear' => true,
);
// [...] more fields added
return $fields;
}
The checkbox behaviour should be similar to this element:
<input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" type="checkbox" name="ship_to_different_address" value="1">
by ticking/unticking this I may show/hide shipping fields. I noticed that these fields are wrapped in a div
How may I do anything similar for my custom checkout fields?
I tried to use this as a guideline: https://wordpress.stackexchange.com/questions/309700/how-to-hook-on-a-woocommerce-checkout-field/309788 without success
I hope I was clear enough in explaining Thanks