Created
October 1, 2019 05:29
-
-
Save ncyhere/44d6a2bd880959da46b67391aad3eedd to your computer and use it in GitHub Desktop.
Woocommerce Remove Billing fields from checkout page if virtual/downloadable product is in cart
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
/** | |
* @snippet Simple Checkout for virtual Products | |
* @author NCY Design https://wordpress.ncy.design | |
* @compatible WooCommerce 3.7.0 | |
*/ | |
add_filter( 'woocommerce_checkout_fields' , 'ncydesign_virtualproduct_checkout' ); | |
function ncydesign_virtualproduct_checkout( $fields ) { | |
$only_virtual = true; | |
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
// Check if there are non-virtual products | |
if ( ! $cart_item['data']->is_virtual() ) $only_virtual = false; | |
} | |
if( $only_virtual ) { | |
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']); | |
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' ); | |
} | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment