Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
function is_product_eligible( $eligible, $product, $discounter_name, $discounter_object ) {
remove_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
if ( $product->is_on_sale() ) {
$eligible = false;
}
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
return $eligible;
}
@no2pixel

This comment has been minimized.

Copy link

@no2pixel no2pixel commented Sep 21, 2015

Would it be possible to extend this filter to simply offer a smaller discount on Sale items?

For example, All users of a specific role get 20% off of the base price of all products in one category, and 10% off of the sale price? I've been trying to use the cumulative discount filter, but I do not seem to be able to determine the specific pricing discount that's being applied and change/apply another.

I have set up 2 advanced_category dynamic pricing rules, one at 20% and one at 10%, and just want to choose which one applies based on the is_on_sale() return value.

@scotcrop

This comment has been minimized.

Copy link

@scotcrop scotcrop commented Mar 17, 2016

If you change the method call for $product to get_sale_price() instead of is_on_sale() it allows you to give a discount to a variation that isn't on sale while not giving it to one that is on sale. Otherwise is_on_sale() blocks all the variations from being marked down.

add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );

function is_product_eligible( $eligible, $product, $discounter_name, $discounter_object ) {

    remove_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );

    if ( $product->get_sale_price() ) {
        $eligible = false;
    }

    add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );

    return $eligible;
}

@zisispaparidis

This comment has been minimized.

Copy link

@zisispaparidis zisispaparidis commented Oct 11, 2017

Is there a way to make $eligible = false a specific discount rule, filtering it by its name? Something like this for example
if ($name == 'discount2') {
$eligible = false;
}
I am trying to figure out which variable is responsible for storing the name of each discount rule, the name that we give in dashboard. So, if I have a discount named "discount2", it would be really really really helpful if one could deactivate this specific discount from within the functions.php file of the theme...

@otherjohn

This comment has been minimized.

Copy link

@otherjohn otherjohn commented Mar 8, 2018

We have applied 10% off all "priced individually" subproducts of a bundle. Dynamic pricing applies its own discount on top of the 10% off. But I want to only discount the dynamic pricing off the true individual retail price, not the 10% off price. How can I go about doing that?

@Intensiver

This comment has been minimized.

Copy link

@Intensiver Intensiver commented Jul 27, 2018

Anyone getting this to work? It's not working whatsoever for me. This basically craches my site (it becomes so slow it's unsuable).

I tried changing the code but it didnt help. Basically I got sale products that I don't want the dynamic discount on (I am using this together with user role editor to give roles %-discount). Any ideas?

@Rana858

This comment has been minimized.

Copy link

@Rana858 Rana858 commented Sep 29, 2019

Hello,

how i can exclude Product Add-Ons from dynamic pricing using your code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment