Skip to content

Instantly share code, notes, and snippets.

@douglsmith
Created July 10, 2014 22:09
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 douglsmith/769fc8dc987633c254a0 to your computer and use it in GitHub Desktop.
Save douglsmith/769fc8dc987633c254a0 to your computer and use it in GitHub Desktop.
WooCommerce Free Virtual Items Checkout
<?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;
}
@ejntaylor
Copy link

I recommend also including the following to hide the Additional Information header: add_filter('woocommerce_enable_order_notes_field', '__return_false');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment