Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function woo_discount_rules_exclude_cart_item_from_discount_method($excluded_products, $rule, $variants){
  2.  
  3. $eligible_rule_id = 9999; // enter the rule ID that applies for downloadable product only
  4.  
  5. if(isset($rule->ID) && $rule->ID == $eligible_rule_id ) {
  6.  
  7. $query = new WC_Product_Query( array(
  8. 'downloadable' => false,
  9. 'return' => 'ids',
  10. ) );
  11. $products = $query->get_products();
  12. if(!empty($products) && is_array($products) && count($products)) {
  13.  
  14.  
  15. $all_products_to_exclude = array_merge ($excluded_products, $products);
  16. foreach($all_products_to_exclude as $product_id) {
  17. $product_ids_to_exclude[] = intval($product_id);
  18. }
  19. $excluded_products = $all_products_to_exclude;
  20. }
  21.  
  22. }
  23.  
  24. return $excluded_products;
  25. }
  26. add_filter('woo_discount_rule_products_to_exclude', 'woo_discount_rules_exclude_cart_item_from_discount_method', 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement