I am using WooCommerce Dynamic pricing, and trying to have it run on my site on all products but excluding those products that are on sale.
Here's the code I tried with, but it's not working at all. Here's the code that WooCommerce Dynamic pricing docs suggest (that breaks my site)
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;
}
Here is the code I tried and that doesn't break my site but doesn't work:
function is_product_eligible( $eligible, $product, $discounter_name, $discounter_object ) {
if ( $product->is_on_sale() ) {
$eligible = false;
}
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
return $eligible;
}