I have a doubt about the work done on the checkout page. It seems to work but I do not know if the procedure is correct or maybe it is possible to do it in a cleaner way. I needed to hide some fields from the billing form that refer to an invoice request that is optional. Then immediately after the form I hooked a hook with a text "Do you need the bill?" and clicking on it with jQuery opens a specific div. My intent was to make appear in this div fields related to the invoice request, for example VAT number etc .. Here is what I did: I overridden the form-billing.php file and hid the default view of the billing field:
<div class="woocommerce-billing-fields__field-wrapper">
<?php
$fields = $checkout->get_checkout_fields( 'billing' );
foreach ( $fields as $key => $field ) {
if ( isset( $field['country_field'], $fields[ $field['country_field'] ] ) ) {
$field['country'] = $checkout->get_value( $field['country_field'] );
}
if ($field['label'] != 'Partita Iva') {
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
}
}
?>
</div>
Then in the functions.php I inserted the following code:
add_action( 'woocommerce_after_checkout_billing_form', 'fattura_elettronica_garage' );
function fattura_elettronica_garage(){ ?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 mt-2 mb-2">
<div id="click_fattura" class="caffeita_need_invoice_block pt-1 pb-1 pl-2 pr-2">
<a class="" data-toggle="collapse" aria-expanded="true">
<h3 class="orange mt-0">HAI BISOGNO DELLA FATTURA?</h3>
</a>
</div>
<div id="fattura" class="" aria-expanded="true" style="">
<div class="woocommerce-billing-fields__field-wrapper">
<?php
$checkout = new WC_Checkout();
$fields = $checkout->get_checkout_fields( 'billing' );
foreach ( $fields as $key => $field ) {
if ( isset( $field['country_field'], $fields[ $field['country_field'] ] ) ) {
$field['country'] = $checkout->get_value( $field['country_field'] );
}
if ($field['label'] == 'Partita Iva') {
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
}
}
?>
<?php do_action( 'woocommerce_after_checkout_billing_form', $checkout ); ?>
</div>
</div>
</div>
<?}
the div
<div id="fattura" class="" aria-expanded="true" >
open it with jquery. Is this the right way to do all this? thanks for those who have the patience to answer
Aucun commentaire:
Enregistrer un commentaire