Created
July 10, 2014 22:09
-
-
Save douglsmith/769fc8dc987633c254a0 to your computer and use it in GitHub Desktop.
WooCommerce Free Virtual Items Checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WooCommerce Free Virtual Items Checkout | |
* Description: Hides most of the checkout fields for orders with only free virtual items. Vistors are more likely to download a free item if an address and phone is not required. | |
* Version: 1.0 | |
* Author: Doug Smith | |
* Author URI: http://smithsrus.com/ | |
*/ | |
defined('WPINC') or die; // Exit if accessed directly | |
add_filter( 'woocommerce_checkout_fields' , 'sru_limit_checkout_fields' ); | |
/** | |
* Remove checkout fields for free, virtual item orders. | |
* | |
* @return $fields array | |
*/ | |
function sru_limit_checkout_fields( $fields ) { | |
global $woocommerce; | |
if( ! $woocommerce->cart->needs_shipping() && 0 == $woocommerce->cart->get_cart_total() ) { | |
unset($fields['billing']['billing_company']); | |
unset($fields['billing']['billing_address_1']); | |
unset($fields['billing']['billing_address_2']); | |
unset($fields['billing']['billing_city']); | |
unset($fields['billing']['billing_postcode']); | |
unset($fields['billing']['billing_country']); | |
unset($fields['billing']['billing_state']); | |
unset($fields['billing']['billing_phone']); | |
unset($fields['order']['order_comments']); | |
} | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend also including the following to hide the Additional Information header: add_filter('woocommerce_enable_order_notes_field', '__return_false');