Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Balakrishnan-flycart/7f2fd5672d55cd1cd1054febbc0297fb to your computer and use it in GitHub Desktop.
Save Balakrishnan-flycart/7f2fd5672d55cd1cd1054febbc0297fb to your computer and use it in GitHub Desktop.
Remove free hidden product dynamically if not match cart rule condition
add_action('woocommerce_before_cart', function(){
if(class_exists('FlycartWooDiscountRulesCartRules')){
if(empty(FlycartWooDiscountRulesCartRules::$applied_coupon)){
if(!empty(WC()->cart)){
$cart_items = WC()->cart->get_cart();
foreach ($cart_items as $key => $cart_item){
$not_visible = false;
$product = $cart_item['data'];
if(method_exists($product, 'is_visible')){
if(!$product->is_visible()){
$not_visible = true;
}
} else if(method_exists($product, 'variation_is_visible')){
if(!$product->variation_is_visible()){
$not_visible = true;
}
}
if($not_visible){
WC()->cart->remove_cart_item( $key );
}
}
}
}
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment