I hope this message finds you well. I am reaching out regarding an issue I am experiencing with your WordPress theme. I have been trying to remove certain billing fields from the WooCommerce checkout page using a custom snippet, but it seems that the fields are not being removed as expected.
Hi,
I hope this message finds you well. I am reaching out regarding an issue I am experiencing with your WordPress theme. I have been trying to remove certain billing fields from the WooCommerce checkout page using a custom snippet, but it seems that the fields are not being removed as expected.
Here is the snippet I am using:
add_filter( 'woocommerce_blocks_checkout_fields', 'remove_billing_fields_for_virtual_product' );
function remove_billing_fields_for_virtual_product( $fields ) {
// Check if the cart contains a virtual product
if ( WC()->cart && ! WC()->cart->needs_shipping() ) {
// Rimuovi tutti i campi di fatturazione eccetto l'email
unset( $fields['billing']['billing_first_name'] );
unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_city'] );
unset( $fields['billing']['billing_postcode'] );
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_state'] );
}
return $fields;
}
While this snippet has worked successfully for other clients using different themes, it does not seem to be effective with your theme.
Could you please assist me in resolving this issue? I would greatly appreciate any guidance or suggestions you can provide.
Thank you very much for your attention to this matter.
Best regards,
Roberto
Hi,
In this case, I recommend that you install the Flexible Checkout Fields plugin from this link: https://wordpress.org/plugins/flexible-checkout-fields/
This lightweight plugin allows you to easily turn on/off any checkout fields.
Regards,
PenciDesign.