Wordpress - radio button checkout woocommerce show / hide required field

I am Italian (sorry for my English) and I am not a programmer.

I need to insert a radio button with two possible answers to this question on my website for ordering woocommerce: "Sei un privato cittadino, un'azienda o un libero professionista?". These are the options: 1) Privato cittadino - 2) Azienda o libero professionista. When users click on the first option, it should display the required field: "codice fiscale". When users click on the second option, it should display two required fields: "P.Iva" and "Ragione sociale". I created a radio field with this code in the form-billing.php:

    <div class="woocommerce-billing-fields">
    <?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>

        <h3><?php _e( 'Billing &amp; Shipping', 'woocommerce' ); ?></h3>

    <?php else : ?>

        <h3><?php _e( 'Billing Details', 'woocommerce' ); ?></h3>
<?
if($key=='billing_first_name')
{
?>
<p>Sei un privato cittadino, un'azienda o un libero professionista?</p>
<input type="radio" name="choice" value="privato_cittadino">Privato cittadino
<input type="radio" name="choice" value="azienda_professionista">Azienda o libero professionista<br>
<?
}
?>
    <?php endif; ?>

, , , . ? , , .

+4

Source: https://habr.com/ru/post/1653715/


All Articles