Here is a snippet that you can use to add the VAT and social name fields in the WooCommerce checkout area.
This code inserts iMandatory fields VAT and company namein Woocommerce.
// Aggiungi i campi Partita IVA e Ragione Sociale nel checkout di WooCommerce add_action('woocommerce_after_checkout_billing_form', 'aggiungi_campi_partita_iva_e_ragione_sociale'); function aggiungi_campi_partita_iva_e_ragione_sociale( $checkout ) { echo ''; } // Validazione dei campi Partita IVA e Ragione Sociale add_action('woocommerce_checkout_process', 'valida_campi_partita_iva_e_ragione_sociale'); function valida_campi_partita_iva_e_ragione_sociale() { if ( ! empty( $_POST['partita_iva'] ) && ! preg_match('/d{11}/', $_POST['partita_iva'] ) ) { wc_add_notice( __( 'La Partita IVA non è valida.', 'woocommerce' ), 'error' ); } if ( empty( $_POST['ragione_sociale'] ) ) { wc_add_notice( __( 'La Ragione Sociale è obbligatoria.', 'woocommerce' ), 'error' ); } } // Salvataggio dei dati Partita IVA e Ragione Sociale nell'ordine add_action('woocommerce_checkout_update_order_meta', 'salva_partita_iva_e_ragione_sociale'); function salva_partita_iva_e_ragione_sociale( $order_id ) { if ( ! empty( $_POST['partita_iva'] ) ) { update_post_meta( $order_id, 'Partita IVA', sanitize_text_field( $_POST['partita_iva'] ) ); } if ( ! empty( $_POST['ragione_sociale'] ) ) { update_post_meta( $order_id, 'Ragione Sociale', sanitize_text_field( $_POST['ragione_sociale'] ) ); } }
Il codice che segue inserisce i campi NON obbligatori Partita Iva e ragione Sociale in Woocommerce.
function aggiungi_campi_partita_iva_e_ragione_sociale( $checkout ) { echo 'Published in '; } add_action( 'woocommerce_checkout_before_customer_details', 'aggiungi_campi_partita_iva_e_ragione_sociale' ); // Salvataggio dei dati Partita IVA e Ragione Sociale nell'ordine add_action( 'woocommerce_checkout_update_order_meta', 'salva_partita_iva_e_ragione_sociale' ); function salva_partita_iva_e_ragione_sociale( $order_id ) { if ( ! empty( $_POST['partita_iva'] ) ) { update_post_meta( $order_id, 'Partita IVA', sanitize_text_field( $_POST['partita_iva'] ) ); } if ( ! empty( $_POST['ragione_sociale'] ) ) { update_post_meta( $order_id, 'Ragione Sociale', sanitize_text_field( $_POST['ragione_sociale'] ) ); } }WordPress
Comment first