ciao!

ho aggiunto questo pezzo di codice nel functions.php del template:
codice:
add_action('woocommerce_before_checkout_form', 'conditionally_show_hide_checkout_field');
function conditionally_show_hide_checkout_field() {
    ?>
    <style>
        p.on {
            display: none !important;
        }
    </style>

    <script type="text/javascript">
        window.onload = function () {
            const chkTrigger = document.querySelector('input#checkbox_trigger');

            chkTrigger.addEventListener('change', ev => {
                if (ev.target.checked) {
                    document.querySelectorAll('.to_hide').forEach(it => {
                        it.classList.remove('on');
                        it.style.display = 'block';
                    });
                } else {
                    document.querySelectorAll('.to_hide').forEach(it => {
                        const currInput = document.getElementById(it.id).querySelector('input[type="text"]');
                        currInput.value = '';
                        it.classList.add('on');
                        it.style.display = 'none';
                    });
                }
            });
        }
    </script>
    <?php
}

add_filter('woocommerce_checkout_fields', 'add_custom_checkout_fields');
function add_custom_checkout_fields($fields) {

    $fields['billing']['checkbox_trigger'] = array(
        'type' => 'checkbox',
        'label' => __('Vuoi richiedere la fattura?', 'woocommerce'),
        'class' => array('form-row-wide'),
        'clear' => true,
    );

    $fields['billing']['rag_soc_field'] = array(
        'label' => __('Denominazione', 'woocommerce'),
        'class' => array('form-row-wide on to_hide'),
        'clear' => true
    );

    $fields['billing']['piva_field'] = array(
        'label' => __('Partita IVA', 'woocommerce'),
        'class' => array('form-row-wide on to_hide'),
        'clear' => true
    );

    $fields['billing']['cf_field'] = array(
        'label' => __('Codice Fiscale', 'woocommerce'),
        'class' => array('form-row-wide on to_hide'),
        'clear' => true
    );

    $fields['billing']['pec_field'] = array(
        'label' => __('PEC', 'woocommerce'),
        'class' => array('form-row-wide on to_hide'),
        'clear' => true,
    );

    $fields['billing']['sdi_field'] = array(
        'label' => __('SDI', 'woocommerce'),
        'class' => array('form-row-wide on to_hide'),
        'clear' => true
    );

    $fields['billing']['indirizzo_field'] = array(
        'label' => __('Indirizzo', 'woocommerce'),
        'class' => array('form-row-wide on to_hide'),
        'clear' => true
    );

    return $fields;
}
funziona, nel senso che nel checkout vedo la checkbox, e quando la seleziono vedo gli altri campi.
il problema è che quando li compilo ed invio l'ordine, questi non vengono visualizzati da nessuna parte.
ne nell'ordine, ne nelle email,. ecc.

qualche idea??