I have an ecommerce webiste using woocommerce In the checkout page I need to activate a custom required field "Codice Fiscale" if the billing country is set to "Italy", otherwise that extra field must be removed The code in my child theme functions.php is
add_filter( 'woocommerce_checkout_fields' , 'field_cfpiva1' );
function field_cfpiva1( $fields ) {
$fields['billing']['billing_cf'] = array(
'label' => __('Codice Fiscale', 'woocommerce'),
'placeholder' => _x('Codice Fiscale', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
add_filter( 'woocommerce_admin_billing_fields' , 'admin_field_cfpiva1' );
function admin_field_cfpiva1( $fields ) {
$fields['cf'] = array(
'label' => __('Codice Fiscale', 'woocommerce'),
'show' => true
);
return $fields;
}
But I've no idea on how to do this dynamically on country change