teseting removal of billing details for free products in woocommerce
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 16 Sep 2016 20:46:27 +0000 (16:46 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 16 Sep 2016 20:46:27 +0000 (16:46 -0400)
functions.php

index 0b5ab23..f309f14 100644 (file)
@@ -232,4 +232,29 @@ if ( ! function_exists('tinyMceEditor_css') ) {
 }
 add_filter( 'mce_css', 'tinyMceEditor_css' );
 
+function remove_billing_fields( $fields ) {
+       global $woocommerce;
+       // if the total is more than 0 then we still need the fields
+       if ( 0 != $woocommerce->cart->total ) {
+               return $fields;
+       }
+       // return the regular billing fields if we need shipping fields
+       if ( $woocommerce->cart->needs_shipping() ) {
+               return $fields;
+       }
+  // we don't need the billing fields so empty all of them except the email
+  unset( $fields['billing_country'] );
+  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_city'] );
+  unset( $fields['billing_state'] );
+  unset( $fields['billing_postcode'] );
+  unset( $fields['billing_phone'] );
+       return $fields;
+}
+add_filter( 'woocommerce_billing_fields', 'remove_billing_fields', 20 );
+
 ?>