From 5dac8f526c65d13e1c58ec6b39b1a471872bd80a Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 27 Sep 2016 15:54:27 -0400 Subject: [PATCH] removing billing details from cart if product is free --- functions.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/functions.php b/functions.php index f88f75d..26280e4 100644 --- a/functions.php +++ b/functions.php @@ -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 -- 2.17.1