Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshlinRejo/46410bb7295afd592ffbd7416be8f3c8 to your computer and use it in GitHub Desktop.
Save AshlinRejo/46410bb7295afd592ffbd7416be8f3c8 to your computer and use it in GitHub Desktop.
Discount rules: Compatible with Booster for WooCommerce
/**
* Compatible with booster plugin https://booster.io/shop/booster-for-woocommerce-plus-plugin/
*
* Limitations:
* Works only for Fixed option for Per product settings in Booster settings
* */
add_filter('wcj_price_by_user_role_get_price', 'wcj_price_by_user_role_get_price_compatible_with_discount_rules', 10, 2);
function wcj_price_by_user_role_get_price_compatible_with_discount_rules($return, $_product){
remove_filter('wcj_price_by_user_role_get_price', 'wcj_price_by_user_role_get_price_compatible_with_discount_rules', 10, 2);
global $flycart_woo_discount_rules;
if(!empty($flycart_woo_discount_rules)){
$discountPrice = $flycart_woo_discount_rules->pricingRules->getDiscountPriceOfProduct($_product);
if($discountPrice !== null){
$return = $discountPrice;
}
}
add_filter('wcj_price_by_user_role_get_price', 'wcj_price_by_user_role_get_price_compatible_with_discount_rules', 10, 2);
return $return;
}
add_action('woocommerce_before_calculate_totals', function (){
remove_filter('wcj_price_by_user_role_get_price', 'wcj_price_by_user_role_get_price_compatible_with_discount_rules', 10, 2);
}, 999);
add_action('woocommerce_before_calculate_totals', function (){
add_filter('wcj_price_by_user_role_get_price', 'wcj_price_by_user_role_get_price_compatible_with_discount_rules', 10, 2);
}, 1001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment