Skip to content

Instantly share code, notes, and snippets.

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 seb86/8059092 to your computer and use it in GitHub Desktop.
Save seb86/8059092 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce Remove Billing Fields for Free Virtual Products
* Plugin URI: https://gist.github.com/BFTrick/7873168
* Description: Remove the billing address fields for free virtual orders
* Author: Patrick Rauland
* Author URI: http://patrickrauland.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Patrick Rauland
* @since 1.0
*/
function patricks_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 don't return them!
return array();
}
add_filter( 'woocommerce_billing_fields', 'patricks_billing_fields', 20 );
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function wc_billing_field_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing Address' :
$translated_text = __( '', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );
// That's all folks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment