From: Anthony Talarico Date: Fri, 16 Sep 2016 20:46:27 +0000 (-0400) Subject: teseting removal of billing details for free products in woocommerce X-Git-Tag: v1.0.0^2~24 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=eb020dc661d903556b453322ff0121f9d5477855;p=WP-Themes%2Fcapstone.git teseting removal of billing details for free products in woocommerce --- diff --git a/functions.php b/functions.php index 0b5ab23..f309f14 100644 --- a/functions.php +++ b/functions.php @@ -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 ); + ?>