Skip to content

Instantly share code, notes, and snippets.

@Sjors
Created May 27, 2022 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sjors/e33495f5cd02621a1a2e179a3d3c99a9 to your computer and use it in GitHub Desktop.
Save Sjors/e33495f5cd02621a1a2e179a3d3c99a9 to your computer and use it in GitHub Desktop.
Disable billing fields for virtual products WooCommerce
add_filter('woocommerce_billing_fields','wpb_custom_billing_fields');
function wpb_custom_billing_fields( $fields = array() ) {
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false');
// No billing details
unset($fields['billing_first_name']);
unset($fields['billing_last_name']);
unset($fields['billing_company']);
unset($fields['billing_address_1']);
unset($fields['billing_address_2']);
unset($fields['billing_state']);
unset($fields['billing_city']);
unset($fields['billing_phone']);
unset($fields['billing_postcode']);
unset($fields['billing_country']);
// Make email optional:
$fields['billing_email']['required'] = false;
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment