Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AshlinRejo/14b676df35af41f4a6451297d79e825b to your computer and use it in GitHub Desktop.
Save AshlinRejo/14b676df35af41f4a6451297d79e825b to your computer and use it in GitHub Desktop.
Discount rules v2: WooCommerce Product Bundles compatible with auto add free product
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