Created
April 27, 2015 06:30
-
-
Save SirDarcanos/fdc05fb78a7ec7c74745 to your computer and use it in GitHub Desktop.
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
/** | |
* Hides checkout fields based on the products in the cart | |
* | |
* @param array $fields | |
* @return array | |
*/ | |
function conditional_checkout_fields_products( $fields ) { | |
$cart = WC()->cart->get_cart(); | |
$has_tag = true; | |
foreach ( $cart as $item_key => $values ) { | |
$product = $values['data']; | |
if ( ! has_term( 'your-tag', 'product_tag', $product->id ) ) { | |
$has_term = false; | |
break; | |
} | |
} | |
if ( $has_term ) { | |
unset( $fields['billing']['billing_company'] ); | |
} | |
return $fields; | |
} | |
add_filter( 'woocommerce_checkout_fields', 'conditional_checkout_fields_products' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment