Solution:
I’ve managed to make it work. I’m posting here in case it could be useful to others
add_action( 'woocommerce_after_checkout_form', 'cbi_cf_conditionally_hide_show', 6);
function cbi_cf_conditionally_hide_show() {
// if ( ICL_LANGUAGE_CODE !='it' ) return; // Only for Italy
$required = esc_attr__( 'required', 'woocommerce' );
?>
<script type="text/javascript">
(function($){
var required = '<abbr class="required" title="<?php echo $required; ?>">*</abbr>'; // Required html
$('#billing_cf_in_field').hide();
$('input[type=radio][name=billing_radiobox_cf]').change(function(){
if (this.value === 'option2') {
$('#billing_cf_in_field').fadeIn("fast", function(){
$(this).addClass("validate-required");
$('#billing_cf_in_field > label').append(required);
});
} else {
$('#billing_cf_in_field').fadeOut("fast", function(){
$(this).removeClass("validate-required");
$('#billing_cf_in_field > label > .required').remove();
});
}
$('#billing_cf_in_field').val('');
$('#billing_cf_in_field').removeClass("woocommerce-validated");
$('#billing_cf_in_field').removeClass("woocommerce-invalid woocommerce-invalid-required-field");
});
})(jQuery);
</script>
<?php
}
Unfortunately, validation is not completely working, since when sending the form, in case billing_cf_in_field is not filled, the field becomes correctly red but the error message does not mention billing_cf_in_field in the list of fields to be fullfilled. I’ll open another thread for this.