Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarancartrabbit/8cf97230a175387649c84dd7d855f87a to your computer and use it in GitHub Desktop.
Save sarancartrabbit/8cf97230a175387649c84dd7d855f87a to your computer and use it in GitHub Desktop.
Woo Discount Rules: Remove cross sell product when add the y product in cart item
add_action('woocommerce_before_cart', function () {
if (class_exists('\WDR\App\Controllers\DiscountCalculator') && class_exists('\WDRPro\App\Rules\Cheapest')) {
$cart = WC()->cart;
$cart_items = $cart->get_cart();
$applied_rules = \WDR\App\Controllers\DiscountCalculator::$applied_rules;
if (!empty($applied_rules)) {
$product_count = 0;
foreach ($applied_rules as $applied_rule) {
if ($applied_rule->rule->discount_type == 'wdr_buy_x_get_y_discount') {
foreach ($cart_items as $cart_item_key => $cart_item) {
if (isset($cart_item['data']->awdr_product_original_price)) {
\WDRPro\App\Rules\Cheapest::$discountable_items['products'] = array();
}
}
}
}
}
}
}, 10);
add_action('woocommerce_before_cart', function () {
?>
<script type="text/javascript">
jQuery(document.body).on('updated_cart_totals', function () {
location.reload();
});
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment