removing billing details from cart if product is free
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 27 Sep 2016 19:54:27 +0000 (15:54 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 27 Sep 2016 19:54:27 +0000 (15:54 -0400)
functions.php

index f88f75d..26280e4 100644 (file)
@@ -300,4 +300,29 @@ class GLM_Members_Only_Walker extends Walker_Nav_Menu {
 }
 endif;
 
+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'] );
+  unset( $fields['billing_email'] );
+       return $fields;
+}
+
 ?>
\ No newline at end of file