Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active June 4, 2019 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bekarice/9432ef8145584dd5c1c9 to your computer and use it in GitHub Desktop.
Save bekarice/9432ef8145584dd5c1c9 to your computer and use it in GitHub Desktop.
Remove WooCommerce checkout add-ons if any product in cart is in a particular category
<?php // only copy if needed
// Remove add-ons if any product in the cart is in the "Gift box" category
function sv_remove_checkout_add_ons_for_giftboxes() {
if ( function_exists( 'wc_checkout_add_ons' ) ) {
$cat_check = false;
// check each cart item for our category
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
// replace 'gift_box' with your category's slug
if ( has_term( 'gift_box', 'product_cat', $product->id ) ) {
$cat_check = true;
// we only need one "true" to leave
break;
}
}
// if a product in the cart is in our category, remove the add-ons
if ( $cat_check ) {
// get the add-ons current position so we know where to remove them from
$position = get_option( 'wc_checkout_add_ons_position' );
remove_action( $position, array( wc_checkout_add_ons()->get_frontend_instance(), 'render_add_ons' ), 20 );
}
}
}
add_action( 'woocommerce_before_checkout_form', 'sv_remove_checkout_add_ons_for_giftboxes' );
@vegaix9
Copy link

vegaix9 commented Jun 16, 2017

This appears to be broken at this time. Checkout Add-ons Version 1.10.4

Checkout Add-ons are no longer hidden if any products in the cart are in category.

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