Created
March 20, 2019 12:56
-
-
Save lucasstark/62d7ffabc8f0f22fa42324d3cc2a1ee8 to your computer and use it in GitHub Desktop.
Exclude specific products from WooCommerce Dynamic Pricing.
This file contains 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_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 ); | |
function is_product_eligible( $eligible, $product, $discounter_name, $discounter_object ) { | |
//Be sure to change this to your product(s) you want to exclude. | |
$exclude_products = array( | |
320, | |
401, | |
100 | |
); | |
$the_id = $product->get_id(); | |
if ( $product->is_type( 'variation' ) ) { | |
$the_id = $product->get_parent_id(); | |
} | |
$exclude = in_array( $the_id, $exclude_products ); | |
return $exclude ? false : $eligible; | |
} | |
add_filter( 'wc_dynamic_pricing_flag_is_on_sale', function ( $on_sale, $product ) { | |
//Be sure to change this to your product(s) you want to exclude. | |
$exclude_products = array( | |
320, | |
401, | |
100 | |
); | |
$the_id = $product->get_id(); | |
if ( $product->is_type( 'variation' ) ) { | |
$the_id = $product->get_parent_id(); | |
} | |
$exclude = in_array( $the_id, $exclude_products ); | |
if ( $exclude ) { | |
return false; | |
} else { | |
return $on_sale; | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment