add_filter( 'advanced_woo_discount_rules_category_taxonomies', function($taxonomy){
// Note: For attributes the taxonomy will be start with prefix pa_
// Example: For attribute Color the taxonomy will be pa_color
$taxonomy[] = 'pa_color';
return $taxonomy;
}, 10);
add_filter('advanced_woo_discount_rules_get_product_categories', function ($categories, $product, $variant){
if(!empty($variant)){
$parant_product = $product;
$product = $variant;
}
$attr_ids = array();
if(class_exists('\Wdr\App\Helpers\Woocommerce')){
$attrs = \Wdr\App\Helpers\Woocommerce::getProductAttributes($product);
if (\Wdr\App\Helpers\Woocommerce::productTypeIs($product, 'variation')) {
if (count(array_filter($attrs)) < count($attrs)) {
if (isset($variant['variation'])) {
$attrs = array();
foreach ($variant['variation'] as $attribute_name => $value) {
$attrs[str_replace('attribute_', '', $attribute_name)] = $value;
}
}
}
foreach ($attrs as $taxonomy => $value) {
if ($value) {
$taxonomy = apply_filters('advanced_woo_discount_rules_attribute_slug', urldecode($taxonomy), $taxonomy, $value);
$term_obj = get_term_by('slug', $value, $taxonomy);
if (!is_wp_error($term_obj) && $term_obj && $term_obj->name) {
$attr_ids = array_merge($attr_ids, (array)($term_obj->term_id));
}
}
}
} else {
foreach ($attrs as $attr) {
$attr_ids = array_merge($attr_ids, \Wdr\App\Helpers\Woocommerce::getAttributeOption($attr));
}
}
}
$categories = (!empty($attr_ids)) ? array_unique($attr_ids) : $categories;
return $categories;
}, 10, 3);
Woo Discount Rules v2 - Implement attribute based bxgy discount
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.