Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucasstark/62d7ffabc8f0f22fa42324d3cc2a1ee8 to your computer and use it in GitHub Desktop.
Save lucasstark/62d7ffabc8f0f22fa42324d3cc2a1ee8 to your computer and use it in GitHub Desktop.
Exclude specific products from WooCommerce Dynamic Pricing.
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