Skip to content

Instantly share code, notes, and snippets.

@woogist
Created March 3, 2015 07:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogist/af2b1ab3aa51db18a8bb to your computer and use it in GitHub Desktop.
Save woogist/af2b1ab3aa51db18a8bb to your computer and use it in GitHub Desktop.
Hides checkout fields based on the products in the cart
/**
* 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