1. Home
  2. Knowledge Base
  3. WooCommerce Dynamic Pricing and Discount Rules
  4. Set discount rules by taxonomy or tag
  1. Home
  2. Knowledge Base
  3. Advanced Topics for Dynamic Pricing and Discount Rules
  4. Set discount rules by taxonomy or tag

Set discount rules by taxonomy or tag

You can set discount rules by taxonomy, tag or attribute by using a filter. The example below shows you how to set a BXGY rule by product brand instead of category:

<?php
/**
* Filter BXGY rule by brand taxonomy instead of category
*/
function demo_bxgy_taxonomy( $taxonomy, $rule, $rule_id ) {
$taxonomy = 'product_brand'; // Change this to the taxonomy or tag of your choice
return $taxonomy;
}
add_filter( 'wcfad_validate_bxgy_rule_taxonomy', 'demo_bxgy_taxonomy', 10, 3 );
function demo_bxgy_buy_categories( $buy_categories, $rule, $rule_id ) {
$buy_categories = array( 34 ); // This is the taxonomy term ID
return $buy_categories;
}
add_filter( 'wcfad_validate_bxgy_rule_buy_categories', 'demo_bxgy_buy_categories', 10, 3 );
function demo_bxgy_get_categories( $get_categories, $rule, $rule_id ) {
$get_categories = array( 33 ); // This is the taxonomy term ID
return $get_categories;
}
add_filter( 'wcfad_validate_bxgy_rule_get_categories', 'demo_bxgy_get_categories', 10, 3 );

Was this article helpful?

Related Articles