Created
August 2, 2022 11:36
-
-
Save AshlinRejo/14b676df35af41f4a6451297d79e825b to your computer and use it in GitHub Desktop.
Discount rules v2: WooCommerce Product Bundles compatible with auto add free product
This file contains hidden or 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
add_action('advanced_woo_discount_rules_after_apply_discount', function (){ | |
$cart_items = WC()->cart->get_cart(); | |
if(!empty($cart_items)){ | |
foreach ($cart_items as $key => $item){ | |
if(isset($item['bundled_by'])){ | |
if(isset($cart_items[$item['bundled_by']])){ | |
$itemParent = $cart_items[$item['bundled_by']]; | |
if(isset($itemParent['data']->is_awdr_free_product) && $itemParent['data']->is_awdr_free_product){ | |
$item['data']->set_price(0); | |
} | |
} | |
} | |
} | |
} | |
}, 20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment