У меня есть несколько условных полей, основанных на переключателе и двух опциях: 1 - Privato 2 Professore
Я пишу код для отображения / скрытия различных полей, но как я могу условно сбросить со стороны сервера и удалить необходимые проверки ? Я смотрю вокруг, но любое решение, которое я нашел, не работает.
О функциях. php file:
function bs_filter_checkout_fields($fields){
$fields['billing'] = array(
'add_type' => array(
'type' => 'radio',
'label' => __( 'Selezione Cliente' ),
'options' => array( 'privato' => __( 'Privato' ), 'professore' => __( 'Professore o Alunno' )),
'required' => true,
'default' => 'privato'
),
'add_nome' => array(
'type' => 'text',
'required' => true,
'placeholder' => __( 'Nome' ),
'label' => __( 'Nome' )
),
'add_cognome' => array(
'type' => 'text',
'required' => true,
'placeholder' => __( 'Cognome' ),
'label' => __( 'Cognome' )
),
'add_email' => array(
'type' => 'text',
'required' => true,
'placeholder' => __( 'Indirizzo email' ),
'label' => __( 'Indirizzo email' )
),
'add_indirizzo' => array(
'type' => 'text',
'required' => true,
'class' => array('private_field'),
'placeholder' => __( 'Indirizzo' ),
'label' => __( 'Indirizzo' )
),
'add_cap' => array(
'type' => 'text',
'required' => true,
'class' => array('private_field'),
'placeholder' => __( 'Cap' ),
'label' => __( 'Cap' )
),
'add_citta' => array(
'type' => 'text',
'required' => true,
'class' => array('private_field'),
'placeholder' => __( 'Città' ),
'label' => __( 'Città' )
),
'add_nome_scuola' => array(
'type' => 'text',
'required' => true,
'class' => array('company_field'),
'placeholder' => __( 'Nome scuola' ),
'label' => __( 'Nome scuola' )
),
'add_citta_scuola' => array(
'type' => 'text',
'required' => true,
'class' => array('company_field'),
'placeholder' => __( 'Città Scuola' ),
'label' => __( 'Città Scuola' )
),
'add_rif_prenotazione' => array(
'type' => 'text',
'required' => true,
'class' => array('company_field'),
'placeholder' => __( 'Riferimento Prenotazione' ),
'label' => __( 'Riferimento Prenotazione' )
),
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'bs_filter_checkout_fields' );
// Hook in
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
$address_fields['add_building_name']['required'] = false;
return $address_fields;
}
function bs_conditional_scripts() {
wc_enqueue_js( "
$( '#add_type_privato' ).change( function () {
if ( $( this ).is( ':checked' ) ) {
$('.company_field').hide();
$( '.private_field' ).show();
}
} ).change();
$( '#add_type_professore' ).change( function () {
if ( $( this ).is( ':checked' ) ) {
$( '.private_field' ).hide();
$('.company_field').show();
}
} ).change();
" );
}