Zero value orders and customer addresses
-
Hi,
I have several products, virtual/downloadable, that are zero value. When a customer adds these to their cart I don’t expect them to be asked for their address on checkout as I have no legitimate reasons to collect this information for free digital products under GDPR. I also don’t want to have to deal with the implications of this.
How can I turn off the need for users to provide an address under this scenario?
Thanks.
-
Hi @paul-filkin,
I can see what you’re aiming for; ensuring customers aren’t prompted to enter unnecessary personal details when checking out with free downloadable products makes perfect sense, especially with GDPR in mind. WooCommerce requires some checkout fields by default, but you can disable them for zero-value virtual or downloadable orders using a code snippet or a plugin.
One effective way is to use a snippet that checks if the cart total is zero, then removes the billing and shipping address fields. You can find clear examples and guidance in our documentation here: https://developer.woocommerce.com/docs/code-snippets/customising-checkout-fields#overriding-core-fields
Alternatively, the plugin “WooCommerce Checkout Field Editor” can help you manage fields without adding custom code: https://woocommerce.com/products/woocommerce-checkout-field-editor/
Once set up, your customers will be able to complete checkout for free digital items without needing to fill in address details. Let’s see how it goes!
Thank you for those references. I have been playing with a code snippets to achieve this but am struggling. I can hide them for zero value totals but then, possibly due to React validation blocking, even when fields are hidden and filled via JavaScript, validation is preventing submission. I hope your tips here will help me with a better approach!
Much appreciated to get your feedback so quickly. Will test now and let you know.
Hi @paul-filkin,
Thanks for the update, it’s great to hear that you’ve already started working on a code snippet to achieve this. I’d like to take a closer look to help pinpoint why validation is still blocking the checkout. Could you please share the snippet you’ve tried so far?
Also, can you confirm which checkout experience your store is using — the classic shortcode-based checkout or the new block-based checkout? This helps determine whether React validation is indeed coming from the checkout blocks or the core validation process.
Once I have those details, I can review the logic and suggest the best way to adjust it so the checkout submits smoothly for zero-value virtual products. Looking forward to your reply!
Hi @lovingbro
The snippet that came closest was attempting to hide billing fields and bypass validation… I had many variants but it was something like this:
add_filter( 'woocommerce_checkout_fields', 'remove_billing_fields_for_free_virtual', 20 );
function remove_billing_fields_for_free_virtual( $fields ) {
if ( WC()->cart->get_total( '' ) == 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item['data'];
if ( $product && $product->is_virtual() ) {
// Remove all billing fields except name and email
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_city'] );
unset( $fields['billing']['billing_state'] );
unset( $fields['billing']['billing_postcode'] );
unset( $fields['billing']['billing_phone'] );
}
}
}
return $fields;
}But the validation still failed… I think because WooCommerce Blocks checkout uses React-based client-side validation that runs independently of server-side filters. But to answer your questions…
Checkout type was WooCommerce Blocks (the new React-based checkout) . The React validation in WooCommerce Blocks seems to require billing address fields even when they’re hidden via PHP filters, and I could not get around the client-side validation preventing form submission before the server-side logic could even run.
So in the end I took a different approach… which is working well for me now.
Rather than fighting WooCommerce’s validation system, I created a completely custom checkout flow that activates only for zero-value carts:
- Detection: Plugin detects when cart total is £0.00 and all items are virtual
- Custom Form: Replaces entire checkout page content with my own form (no WooCommerce classes)
- Minimal Fields: Only collects name and email (GDPR-compliant)
- Spam Protection: added a math CAPTCHA since this opened me up more to potential spam
- AJAX Submission: Bypasses WooCommerce checkout entirely, creates order directly via AJAX
- Auto-login: Creates account and logs user in automatically
The solution seems cleaner, and it provides a better UX than trying to bend WooCommerce Blocks to my needs… especially since I couldn’t do it!
<span style=”font-size: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;”>Hi @paul-filkin,</span>
I appreciate the detailed explanation of the approach you’ve taken, and it’s great to hear you’ve already implemented a custom checkout flow that aligns with your GDPR goals. It sounds like a solid solution that simplifies the user journey while maintaining compliance.
Looking at your earlier snippet, the validation issue makes sense given that WooCommerce Blocks use React-based validation independent of PHP filters. If you ever decide to refine the snippet for the classic checkout instead, you can make a small correction to the condition line:
<code class="language-php">if ( WC()->cart && WC()->cart->get_total( '' ) == 0 ) {Adding the <code inline=””>WC()->cart check ensures the cart object is initialized properly before running <code inline=””>get_total(), preventing potential errors in certain checkout states.
That said, since your custom checkout is working smoothly, it may be best to stick with that cleaner approach. Can you confirm if it’s performing as expected so we can mark this thread as resolved?
Let’s see how it goes!
Yes, working as expected… thank you.
I did think about using the classic checkout but I have other customisations that I was worried about breaking, so decided against it. In the end I quite like the approach I’ve taken as it’s easier to manage now.
Thanks for your help… really appreciate the quick feedback.
Hi @paul-filkin,
Glad we could help point you in the right direction and that your custom checkout flow is working well for your setup. It’s always great to see creative solutions like yours that improve the checkout experience while keeping things GDPR-compliant.
If you’ve been happy with WooCommerce and the support received, we’d really appreciate it if you could take a moment to leave us a 5-star review here: https://wordpress.org/support/plugin/woocommerce/reviews/#new-post
Your feedback helps us continue improving WooCommerce for everyone. Let’s keep the momentum going!
You must be logged in to reply to this topic.