Created
March 3, 2015 07:31
-
-
Save woogist/af2b1ab3aa51db18a8bb to your computer and use it in GitHub Desktop.
Hides checkout fields based on the products in the cart
This file contains 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(); | |
foreach ( $cart as $item_key => $values ) { | |
$product = $values['data']; | |
if ( $product->id == 70 ) { | |
unset( $fields['billing']['billing_company'] ); | |
unset( $fields['shipping']['shipping_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