Aggiungiamo Codice fiscale e Partita IVA ai campi richiesti per l’acquisto da Woocommerce
function my_custom_checkout_fields( $fields ) {
$fields['billing']['billing_codice_fiscale'] = array(
'label' => __('Codice Fiscale', 'woocommerce'),
'placeholder' => _x('Codice Fiscale', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
$fields['billing']['billing_partita_iva'] = array(
'label' => __('Partita IVA', 'woocommerce'),
'placeholder' => _x('Partita IVA', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'my_custom_checkout_fields' );
Mostriamo i due post_meta negli ordini in admin
function my_custom_admin_order_data_after_shipping_address($order){
echo '<p><strong>'.__('Codice Fiscale', 'woocommerce').':</strong> '.get_post_meta( $order->id, '_billing_codice_fiscale', true ).'</p>';
echo '<p><strong>'.__('Partita IVA', 'woocommerce').':</strong> '.get_post_meta( $order->id, '_billing_partita_iva', true ).'</p>';
}
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_admin_order_data_after_shipping_address', 10, 1 );
Mostriamo i due post_meta nelle email inviate con l’ordine
function my_custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['billing_codice_fiscale'] = array(
'label' => __('Codice Fiscale', 'woocommerce'),
'value' => get_post_meta( $order->id, '_billing_codice_fiscale', true ),
);
$fields['billing_partita_iva'] = array(
'label' => __('Partita IVA', 'woocommerce'),
'value' => get_post_meta( $order->id, '_billing_partita_iva', true ),
);
return $fields;
}
add_filter( 'woocommerce_email_order_meta_fields', 'my_custom_woocommerce_email_order_meta_fields', 10, 3 );
Se hai bisogno di aiuto per aggiungere codice fiscale e partita iva al tuo checkout (anche sulla pagina “account” di woocommerce e nel riepilogo ordine) contattami