Discount Rules for WooCommerce - Version 1.7.13

Version Description

  • 02/05/19 =
  • Improvement - Performance improvement, while having large number of rules with specific product options.
  • Improvement - Consider only visible product variations for displaying strikeout.
  • Improvement - Event apply_filters('woo_discount_rules_exclude_product_type_for_sale_price_strikeout_adjustment', $product_types, $product) - Exclude product type for sale price strikeout adjustment.
  • Improvement - Event apply_filters('woo_discount_rules_load_cart_from_woocommerce_object', true) - To load cart from wc() object or $woocommerce variable.
  • Improvement - Event apply_filters('woo_discount_rules_apply_rules', $status) - Run rules or not.
  • Improvement - Event apply_filters('woo_discount_rules_run_price_rule', true, $rule), apply_filters('woo_discount_rules_run_cart_rule', true, $rule) - Enable/Disable specific rule.
  • Improvement - Event apply_filters('woo_discount_rules_woocs_convert_price_based_on_currency', false, $product) - For Woocommerce currency switcher compatible
  • Fix - Displaying same strike out when product is on sale (option - covered under any price based rule).
  • Fix - Loading default language product when WPML is available on product select box.
  • Fix - Not hiding all zero value of coupon while having multiple coupon based rules.
Download this release

Release Info

Developer flycart
Plugin Icon 128x128 Discount Rules for WooCommerce
Version 1.7.13
Comparing to
See all releases

Code changes from version 1.7.12 to 1.7.13

helper/general-helper.php CHANGED
@@ -17,6 +17,8 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
17
  */
18
  public $default_page = 'pricing-rules';
19
 
 
 
20
  /**
21
  * To Process the View.
22
  *
@@ -442,7 +444,7 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
442
  $status = false;
443
  }
444
 
445
- return $status;
446
  }
447
 
448
  public static function haveToApplyTheRules(){
@@ -457,7 +459,7 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
457
  }
458
  }
459
 
460
- return $status;
461
  }
462
 
463
  /**
@@ -696,15 +698,21 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
696
  protected static function getAllSubCategoriesRecursive($cat, $taxonomy = 'product_cat'){
697
  $category_with_sub_cat = $cat;
698
  foreach($cat as $c) {
699
- $args = array('hierarchical' => 1,
700
- 'show_option_none' => '',
701
- 'hide_empty' => 0,
702
- 'parent' => $c,
703
- 'taxonomy' => $taxonomy);
704
- $categories = get_categories( $args );
705
- foreach($categories as $category) {
706
- //$category_with_sub_cat[] = $category->term_id;
707
- $category_with_sub_cat = array_merge($category_with_sub_cat, self::getAllSubCategoriesRecursive(array($category->term_id), $taxonomy));
 
 
 
 
 
 
708
  }
709
  }
710
  $category_with_sub_cat = array_unique($category_with_sub_cat);
@@ -793,7 +801,11 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
793
  if($has_coupon){
794
  if(!empty($styles)){
795
  global $styles_woo_discount;
796
- $styles_woo_discount = $styles;
 
 
 
 
797
  $is_ajax = is_ajax();
798
  $wc_ajax = isset($_REQUEST['wc-ajax'])? $_REQUEST['wc-ajax']: false;
799
  if(!$is_ajax){
17
  */
18
  public $default_page = 'pricing-rules';
19
 
20
+ protected static $sub_categories = array();
21
+
22
  /**
23
  * To Process the View.
24
  *
444
  $status = false;
445
  }
446
 
447
+ return apply_filters('woo_discount_rules_apply_rules', $status);
448
  }
449
 
450
  public static function haveToApplyTheRules(){
459
  }
460
  }
461
 
462
+ return apply_filters('woo_discount_rules_apply_rules', $status);
463
  }
464
 
465
  /**
698
  protected static function getAllSubCategoriesRecursive($cat, $taxonomy = 'product_cat'){
699
  $category_with_sub_cat = $cat;
700
  foreach($cat as $c) {
701
+ if(isset(self::$sub_categories[$c])){
702
+ $category_with_sub_cat = array_merge($category_with_sub_cat, self::$sub_categories[$c]);
703
+ } else {
704
+ $args = array('hierarchical' => 1,
705
+ 'show_option_none' => '',
706
+ 'hide_empty' => 0,
707
+ 'parent' => $c,
708
+ 'taxonomy' => $taxonomy);
709
+ $categories = get_categories( $args );
710
+ foreach($categories as $category) {
711
+ //$category_with_sub_cat[] = $category->term_id;
712
+ $category_with_sub_cat = array_merge($category_with_sub_cat, self::getAllSubCategoriesRecursive(array($category->term_id), $taxonomy));
713
+ }
714
+
715
+ self::$sub_categories[$c] = $category_with_sub_cat;
716
  }
717
  }
718
  $category_with_sub_cat = array_unique($category_with_sub_cat);
801
  if($has_coupon){
802
  if(!empty($styles)){
803
  global $styles_woo_discount;
804
+ if(!empty($styles_woo_discount)){
805
+ $styles_woo_discount .= $styles;
806
+ } else {
807
+ $styles_woo_discount = $styles;
808
+ }
809
  $is_ajax = is_ajax();
810
  $wc_ajax = isset($_REQUEST['wc-ajax'])? $_REQUEST['wc-ajax']: false;
811
  if(!$is_ajax){
helper/woo-function.php CHANGED
@@ -42,6 +42,13 @@ if(!class_exists('FlycartWoocommerceVersion')){
42
 
43
  if(!class_exists('FlycartWoocommerceProduct')){
44
  class FlycartWoocommerceProduct{
 
 
 
 
 
 
 
45
  /**
46
  * Get WooCommerce product
47
  *
@@ -51,7 +58,11 @@ if(!class_exists('FlycartWoocommerceProduct')){
51
  */
52
  public static function wc_get_product($product_id)
53
  {
54
- return FlycartWoocommerceVersion::wcVersion('2.2') ? wc_get_product($product_id) : get_product($product_id);
 
 
 
 
55
  }
56
 
57
  /**
@@ -142,14 +153,19 @@ if(!class_exists('FlycartWoocommerceProduct')){
142
  * @return array
143
  */
144
  public static function get_children($product){
145
- if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product, 'get_children')){
146
- return $product->get_children();
147
- } else {
148
- if(isset($product->children)){
149
- return $product->children;
 
 
 
 
150
  }
151
- return '';
152
  }
 
 
153
  }
154
 
155
  /**
@@ -315,14 +331,34 @@ if(!class_exists('FlycartWoocommerceProduct')){
315
  */
316
  public static function get_variant_ids($product_id)
317
  {
318
- $ids = array();
319
- $productV = new WC_Product_Variable( $product_id );
320
- $variations = $productV->get_available_variations();
321
- if(!empty($variations))
322
- foreach ($variations as $variation) {
323
- $ids[] = $variation['variation_id'];
324
- }
325
- return $ids;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  }
327
 
328
  /**
@@ -338,18 +374,23 @@ if(!class_exists('FlycartWoocommerceProduct')){
338
  $parent = self::get_parent_id($product);
339
  if($parent) $product = self::wc_get_product($parent);
340
  }
341
- $cat_id = array();
342
- if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product, 'get_category_ids')){
343
- $cat_id = $product->get_category_ids();
344
- $cat_id = apply_filters('woo_discount_rules_load_additional_taxonomy', $cat_id, self::get_id($product));
345
- } else {
346
- $terms = get_the_terms ( self::get_id($product), 'product_cat' );
347
- if(!empty($terms))
348
- foreach ( $terms as $term ) {
349
- $cat_id[] = $term->term_id;
350
- }
 
 
 
 
351
  }
352
- return $cat_id;
 
353
  }
354
 
355
  /**
@@ -360,17 +401,20 @@ if(!class_exists('FlycartWoocommerceProduct')){
360
  * @return string
361
  */
362
  public static function get_product_category_by_id( $category_id ) {
363
- $term_name = '';
364
- $taxonomies = apply_filters('woo_discount_rules_accepted_taxonomy_for_category', array('product_cat'));
365
- foreach ($taxonomies as $taxonomy){
366
- $term = get_term_by( 'id', $category_id, $taxonomy, 'ARRAY_A' );
367
- if(!empty($term['name'])){
368
- $term_name = $term['name'];
369
- break;
 
 
370
  }
 
371
  }
372
 
373
- return $term_name;
374
  }
375
 
376
  /*
@@ -474,9 +518,20 @@ if(!class_exists('FlycartWoocommerceCartProduct')){
474
  */
475
  public static function get_cart()
476
  {
477
- if(!empty(WC()->cart)){
478
- return WC()->cart->get_cart();
 
 
 
 
 
 
 
 
 
 
479
  }
 
480
  return array();
481
  }
482
 
42
 
43
  if(!class_exists('FlycartWoocommerceProduct')){
44
  class FlycartWoocommerceProduct{
45
+
46
+ protected static $products = array();
47
+ protected static $products_categories = array();
48
+ protected static $products_variants = array();
49
+ protected static $product_children = array();
50
+ protected static $taxonomy_term_name = array();
51
+
52
  /**
53
  * Get WooCommerce product
54
  *
58
  */
59
  public static function wc_get_product($product_id)
60
  {
61
+ if(isset(self::$products[$product_id])){} else {
62
+ self::$products[$product_id] = FlycartWoocommerceVersion::wcVersion('2.2') ? wc_get_product($product_id) : get_product($product_id);
63
+ }
64
+
65
+ return self::$products[$product_id];
66
  }
67
 
68
  /**
153
  * @return array
154
  */
155
  public static function get_children($product){
156
+ $product_id = self::get_id($product);
157
+ if(isset(self::$product_children[$product_id])){} else {
158
+ if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product, 'get_children')){
159
+ self::$product_children[$product_id] = $product->get_children();
160
+ } else {
161
+ if(isset($product->children)){
162
+ self::$product_children[$product_id] = $product->children;
163
+ }
164
+ self::$product_children[$product_id] = '';
165
  }
 
166
  }
167
+
168
+ return self::$product_children[$product_id];
169
  }
170
 
171
  /**
331
  */
332
  public static function get_variant_ids($product_id)
333
  {
334
+ if(isset(self::$products_variants[$product_id])){} else {
335
+ $ids = array();
336
+ $productV = new WC_Product_Variable( $product_id );
337
+ $variations = $productV->get_available_variations();
338
+ if(!empty($variations))
339
+ foreach ($variations as $variation) {
340
+ $ids[] = $variation['variation_id'];
341
+ }
342
+ self::$products_variants[$product_id] = $ids;
343
+ }
344
+
345
+ return self::$products_variants[$product_id];
346
+ }
347
+
348
+ /**
349
+ * Check variation is visible in frontend
350
+ *
351
+ * @access public
352
+ * @param object $product
353
+ * @return boolean
354
+ */
355
+ public static function variation_is_visible_in_frontend($product)
356
+ {
357
+ if(method_exists($product, 'variation_is_visible')){
358
+ return $product->variation_is_visible();
359
+ }
360
+
361
+ return true;
362
  }
363
 
364
  /**
374
  $parent = self::get_parent_id($product);
375
  if($parent) $product = self::wc_get_product($parent);
376
  }
377
+ $product_id = self::get_id($product);
378
+ if(isset(self::$products_categories[$product_id])){} else {
379
+ $cat_id = array();
380
+ if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product, 'get_category_ids')){
381
+ $cat_id = $product->get_category_ids();
382
+ $cat_id = apply_filters('woo_discount_rules_load_additional_taxonomy', $cat_id, $product_id);
383
+ } else {
384
+ $terms = get_the_terms ( self::get_id($product), 'product_cat' );
385
+ if(!empty($terms))
386
+ foreach ( $terms as $term ) {
387
+ $cat_id[] = $term->term_id;
388
+ }
389
+ }
390
+ self::$products_categories[$product_id] = $cat_id;
391
  }
392
+
393
+ return self::$products_categories[$product_id];
394
  }
395
 
396
  /**
401
  * @return string
402
  */
403
  public static function get_product_category_by_id( $category_id ) {
404
+ if(isset(self::$taxonomy_term_name[$category_id])){} else {
405
+ $term_name = '';
406
+ $taxonomies = apply_filters('woo_discount_rules_accepted_taxonomy_for_category', array('product_cat'));
407
+ foreach ($taxonomies as $taxonomy){
408
+ $term = get_term_by( 'id', $category_id, $taxonomy, 'ARRAY_A' );
409
+ if(!empty($term['name'])){
410
+ $term_name = $term['name'];
411
+ break;
412
+ }
413
  }
414
+ self::$taxonomy_term_name[$category_id] = $term_name;
415
  }
416
 
417
+ return self::$taxonomy_term_name[$category_id];
418
  }
419
 
420
  /*
518
  */
519
  public static function get_cart()
520
  {
521
+ $load_cart_from_wc_object = apply_filters('woo_discount_rules_load_cart_from_woocommerce_object', true);
522
+ if($load_cart_from_wc_object){
523
+ if(!empty(WC()->cart)){
524
+ return WC()->cart->get_cart();
525
+ }
526
+ } else {
527
+ global $woocommerce;
528
+ if(!empty($woocommerce->cart) && !empty($woocommerce->cart)){
529
+ if(!empty($woocommerce->cart->cart_contents)){
530
+ return $woocommerce->cart->cart_contents;
531
+ }
532
+ }
533
  }
534
+
535
  return array();
536
  }
537
 
includes/cart-rules.php CHANGED
@@ -615,9 +615,12 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
615
  if ($validateDate) {
616
  // Validating the Rule with its Order ID.
617
  if (isset($rule->rule_order)) {
618
- // If Order ID is '-', then this rule not going to implement.
619
- if ($rule->rule_order !== '-') {
620
- $rule_set[] = $rule;
 
 
 
621
  }
622
  }
623
  }
@@ -1648,6 +1651,12 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
1648
  */
1649
  public function calculateProductDiscount(array $product_ids = array(), $discount_quantity = 1,$rule_text ="")
1650
  {
 
 
 
 
 
 
1651
  if (empty($product_ids))
1652
  return true;
1653
  if(empty($rule_text))
615
  if ($validateDate) {
616
  // Validating the Rule with its Order ID.
617
  if (isset($rule->rule_order)) {
618
+ $load_rule = apply_filters('woo_discount_rules_run_cart_rule', true, $rule);
619
+ if($load_rule){
620
+ // If Order ID is '-', then this rule not going to implement.
621
+ if ($rule->rule_order !== '-') {
622
+ $rule_set[] = $rule;
623
+ }
624
  }
625
  }
626
  }
1651
  */
1652
  public function calculateProductDiscount(array $product_ids = array(), $discount_quantity = 1,$rule_text ="")
1653
  {
1654
+ $have_to_do = apply_filters('woo_discount_rules_process_cart_bogo_auto_add', true);
1655
+
1656
+ if(!$have_to_do){
1657
+ return true;
1658
+ }
1659
+
1660
  if (empty($product_ids))
1661
  return true;
1662
  if(empty($rule_text))
includes/discount-base.php CHANGED
@@ -773,7 +773,7 @@ if (!class_exists('FlycartWooDiscountBase')) {
773
 
774
  $helper = new FlycartWooDiscountRulesGeneralHelper();
775
  $isPro = $helper->checkPluginState();
776
-
777
  switch ($type) {
778
  // Managing Price Rules View.
779
  case 'pricing-rules':
@@ -860,6 +860,25 @@ if (!class_exists('FlycartWooDiscountBase')) {
860
 
861
  }
862
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
863
  /**
864
  * @return array
865
  */
773
 
774
  $helper = new FlycartWooDiscountRulesGeneralHelper();
775
  $isPro = $helper->checkPluginState();
776
+ $this->checkForWPMLAndSetCookie($type);
777
  switch ($type) {
778
  // Managing Price Rules View.
779
  case 'pricing-rules':
860
 
861
  }
862
 
863
+ /**
864
+ * Check for WPML available and set cookie if available
865
+ * */
866
+ protected function checkForWPMLAndSetCookie($layout){
867
+ $set_wpml_lang = apply_filters('woo_discount_rules_set_wpml_language_for_loading_in_product_select_box', true);
868
+ if($set_wpml_lang){
869
+ $wpml_language = FlycartWooDiscountRulesGeneralHelper::getWPMLLanguage();
870
+ if(!empty($wpml_language)){
871
+ if(in_array($layout, array('pricing-rules-new', 'pricing-rules-view', 'cart-rules-view', 'cart-rules-new'))){
872
+ setcookie('_wcml_dashboard_order_language', $wpml_language, time() + 86400, COOKIEPATH, COOKIE_DOMAIN);
873
+ } else {
874
+ if(!isset($_COOKIE['_wcml_dashboard_order_language']) && !empty($_COOKIE['_wcml_dashboard_order_language'])) {
875
+ setcookie('_wcml_dashboard_order_language', '', time() + 86400, COOKIEPATH, COOKIE_DOMAIN);
876
+ }
877
+ }
878
+ }
879
+ }
880
+ }
881
+
882
  /**
883
  * @return array
884
  */
includes/pricing-rules.php CHANGED
@@ -69,6 +69,11 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
69
 
70
  public $bogo_matches;
71
 
 
 
 
 
 
72
  public static $rules_loaded = 0;
73
  public static $rules_applied_already = 0;
74
  public static $pricingRules;
@@ -172,6 +177,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
172
  'subtotal_to_apply',
173
  'exclude_sale_items',
174
  'wpml_language',
 
 
 
175
  );
176
 
177
  //----------------------------------------------------------------------------------------------------------
@@ -263,16 +271,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
263
 
264
  foreach ($request['discount_range'] as $index => $value) {
265
  $request['discount_range'][$index] = FlycartWooDiscountRulesGeneralHelper::makeString($value);
 
266
  $request['discount_range'][$index]['title'] = isset($request['rule_name']) ? $request['rule_name'] : '';
267
 
268
  }
269
-
270
  $request['discount_range'] = json_encode($request['discount_range']);
271
  } else {
272
  // Reset the Discount Range, if its empty.
273
  $request['discount_range'] = '';
274
  }
275
  if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
 
276
  $request['product_based_condition'] = json_encode($request['product_based_condition']);
277
  $request['product_based_discount'] = json_encode($request['product_based_discount']);
278
  } else {
@@ -291,7 +300,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
291
 
292
  $request['status'] = 'publish';
293
  $request['wpml_language'] = FlycartWooDiscountRulesGeneralHelper::getWPMLLanguage();
294
-
295
  if (is_null($id) || !isset($id)) return false;
296
  FlycartWooDiscountRulesGeneralHelper::resetUsedCoupons($id, $coupons_used);
297
  foreach ($request as $index => $value) {
@@ -308,6 +317,50 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
308
  $this->updateLastUpdateTimeOfRule();
309
  }
310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
 
312
  /**
313
  * For update the last update time of rule
@@ -474,6 +527,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
474
  */
475
  public function filterRules()
476
  {
 
 
 
477
  $rules = $this->rules;
478
 
479
  if (is_null($rules) || !isset($rules)) return false;
@@ -491,12 +547,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
491
  $validateDate = FlycartWooDiscountRulesGeneralHelper::validateDateAndTime($date_from, $date_to);
492
  // Validating Rule with Date of Expiry.
493
  if ($validateDate) {
494
-
495
  // Validating the Rule with its Order ID.
496
  if (isset($rule->rule_order)) {
497
- // If Order ID is '-', then this rule not going to implement.
498
- if ($rule->rule_order !== '-') {
499
- $rule_set[] = $rule;
 
 
 
500
  }
501
  }
502
  }
@@ -508,6 +566,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
508
 
509
  // To Order the Rules, based on its order ID.
510
  $this->orderRules();
 
 
511
  }
512
 
513
  /**
@@ -776,6 +836,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
776
  */
777
  public function generateRuleSets($woocommerce)
778
  {
 
 
 
779
  $rule_sets = array();
780
 
781
  if (!isset($this->rules)) return false;
@@ -805,7 +868,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
805
  if ($rule->apply_to == 'specific_products') {
806
  if (isset($rule->product_to_apply)) {
807
  $rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
808
- $rule_sets[$index]['type']['specific_products'] = apply_filters('woo_discount_rule_products_to_include', $rule_sets[$index]['type']['specific_products'], $rule);
 
 
809
  }
810
  if (isset($rule->is_cumulative_for_products) && $rule->is_cumulative_for_products) {
811
  $rule_sets[$index]['is_cumulative_for_products'] = 1;
@@ -916,7 +981,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
916
  $rule_sets[$index]['product_based_discount'] = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
917
  }
918
  }
919
- $this->rule_sets = $rule_sets;
 
 
920
  }
921
 
922
  /**
@@ -1378,10 +1445,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1378
  $quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
1379
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
1380
  $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
1381
- $product_to_buy = apply_filters('woo_discount_rule_products_to_include', $product_to_buy, $rule);
 
 
1382
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
1383
  $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
1384
- $product_to_apply = apply_filters('woo_discount_rule_products_to_include', $product_to_apply, $rule);
 
 
1385
  $category_to_apply = isset($product_based_conditions['category_to_apply']) ? $product_based_conditions['category_to_apply'] : array();
1386
  $get_discount_type = isset($product_based_conditions['get_discount_type']) ? $product_based_conditions['get_discount_type'] : 'product';
1387
 
@@ -1666,7 +1737,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1666
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
1667
  $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
1668
  if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'any_cheapest'){
1669
- $productIds = apply_filters('woo_discount_rule_products_to_include', $productIds, $discount_ranges);
 
 
1670
  }
1671
  if($discount_product_option == 'same_product'){
1672
  $productId = FlycartWoocommerceProduct::get_id($item['data']);
@@ -2408,10 +2481,12 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2408
  if (in_array($id, $products_to_apply)) {
2409
  $status = true;
2410
  }
2411
- $variations = FlycartWoocommerceProduct::get_variant_ids($product_id);
2412
- if(!empty($variations)){
2413
- if (count(array_intersect($variations, $products_to_apply)) > 0) {
2414
- $status = true;
 
 
2415
  }
2416
  }
2417
  }
@@ -2550,7 +2625,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2550
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
2551
  if(is_array($children) && count($children)){
2552
  foreach ( $children as $child ) {
2553
- if ( '' !== FlycartWoocommerceProduct::get_price($child) ) {
 
2554
  $childProducts[] = FlycartWoocommerceProduct::get_id($child);
2555
  }
2556
  }
@@ -2624,8 +2700,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2624
  if(!is_array($productToExclude)){
2625
  $productToExclude = array();
2626
  }
 
 
2627
 
2628
- $productToExclude = apply_filters('woo_discount_rule_products_to_exclude', $productToExclude, $rule);
2629
 
2630
  return $productToExclude;
2631
  }
@@ -3167,8 +3245,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3167
  $currencies = $WOOCS->get_currencies();
3168
  $is_geoip_manipulation = $WOOCS->is_geoip_manipulation;
3169
  $woocs_is_fixed_enabled = $WOOCS->is_fixed_enabled;
 
3170
  //woocs_is_geoip_manipulation //woocs_is_fixed_enabled
3171
- if($is_geoip_manipulation || $woocs_is_fixed_enabled){
3172
  $amount = $amount / $currencies[$WOOCS->current_currency]['rate'];
3173
  }
3174
  }
@@ -3404,7 +3483,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3404
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3405
  }
3406
  $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
3407
- $item_price = '<span class="cart_price wdr_product_strikeout"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix($discountPrice) . '</ins></span>';
 
 
3408
  $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
3409
  }
3410
  }
@@ -3418,8 +3499,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3418
  $show_sale_tag_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'show';
3419
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_price_discount_on_product_page']))? $this->baseConfig['show_price_discount_on_product_page']: 'show';
3420
  if($show_sale_tag_on_product_page == 'show_on_any_rules_matches' || ($show_sale_tag_on_product_page == 'show' && $show_price_discount_on_product_page == 'dont')) {
3421
- if (!$product->is_type(array('variable', 'subscription_variation', 'variable-subscription', 'grouped'))) {
3422
- $product_id = FlycartWoocommerceProduct::get_id($product);
 
 
3423
  // if(!empty(self::$product_on_sale_details[$product_id])){
3424
  $sale_price = FlycartWoocommerceProduct::get_price($product);
3425
  $regular_price = FlycartWoocommerceProduct::get_regular_price($product);
@@ -3430,6 +3513,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3430
  return $item_price;
3431
  }
3432
  // }
 
3433
  }
3434
  }
3435
 
@@ -3487,7 +3571,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3487
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3488
  }
3489
  $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
3490
- $item_price = '<span class="cart_price wdr_product_strikeout"><del>' . $item_price . '</del> <ins>' . (self::$product_has_strike_out[$product_id]['new_strikeout_html']) . '</ins></span>';
 
 
3491
  $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
3492
  }
3493
  } else {
@@ -3576,7 +3662,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3576
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
3577
  if(is_array($children) && count($children)){
3578
  foreach ( $children as $child ) {
3579
- if ( '' !== FlycartWoocommerceProduct::get_price($child) ) {
 
3580
  $child_prices[FlycartWoocommerceProduct::get_id($child)] = 'incl' === $tax_display_mode ? FlycartWoocommerceProduct::get_price_including_tax($child) : FlycartWoocommerceProduct::get_price_excluding_tax( $child );
3581
  }
3582
  }
@@ -3646,7 +3733,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3646
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
3647
  if(is_array($children) && count($children)){
3648
  foreach ( $children as $child ) {
3649
- if ( '' !== FlycartWoocommerceProduct::get_price($child) ) {
 
3650
  $child_prices[FlycartWoocommerceProduct::get_id($child)] = 'incl' === $tax_display_mode ? FlycartWoocommerceProduct::get_price_including_tax($child) : FlycartWoocommerceProduct::get_price_excluding_tax( $child );
3651
  }
3652
  }
@@ -3749,7 +3837,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3749
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
3750
  if(is_array($children) && count($children)){
3751
  foreach ( $children as $child ) {
3752
- if ( '' !== FlycartWoocommerceProduct::get_price($child) ) {
 
3753
  $discountPrice = $this->getDiscountPriceForTheProduct($child);
3754
  if($discountPrice > 0){
3755
  $on_sale = true;
69
 
70
  public $bogo_matches;
71
 
72
+ public static $rules_filtered = 0;
73
+ public static $filtered_rules = array();
74
+ public static $rule_sets_generated = 0;
75
+ public static $generated_rule_sets = array();
76
+
77
  public static $rules_loaded = 0;
78
  public static $rules_applied_already = 0;
79
  public static $pricingRules;
177
  'subtotal_to_apply',
178
  'exclude_sale_items',
179
  'wpml_language',
180
+ 'product_to_exclude_variants',
181
+ 'product_to_apply_variants',
182
+ 'purchase_history_products_variants',
183
  );
184
 
185
  //----------------------------------------------------------------------------------------------------------
271
 
272
  foreach ($request['discount_range'] as $index => $value) {
273
  $request['discount_range'][$index] = FlycartWooDiscountRulesGeneralHelper::makeString($value);
274
+ $request['discount_range'][$index] = $this->addVariantProducts($request['discount_range'][$index]);
275
  $request['discount_range'][$index]['title'] = isset($request['rule_name']) ? $request['rule_name'] : '';
276
 
277
  }
 
278
  $request['discount_range'] = json_encode($request['discount_range']);
279
  } else {
280
  // Reset the Discount Range, if its empty.
281
  $request['discount_range'] = '';
282
  }
283
  if(isset($request['rule_method']) && $request['rule_method'] == 'product_based'){
284
+ $request['product_based_condition'] = $this->addVariantProducts($request['product_based_condition']);
285
  $request['product_based_condition'] = json_encode($request['product_based_condition']);
286
  $request['product_based_discount'] = json_encode($request['product_based_discount']);
287
  } else {
300
 
301
  $request['status'] = 'publish';
302
  $request['wpml_language'] = FlycartWooDiscountRulesGeneralHelper::getWPMLLanguage();
303
+ $request = $this->addVariantProducts($request);
304
  if (is_null($id) || !isset($id)) return false;
305
  FlycartWooDiscountRulesGeneralHelper::resetUsedCoupons($id, $coupons_used);
306
  foreach ($request as $index => $value) {
317
  $this->updateLastUpdateTimeOfRule();
318
  }
319
 
320
+ /**
321
+ * Add variants of the products for storing with rule
322
+ * */
323
+ protected function addVariantProducts($request){
324
+ $get_variants_for = array('product_to_apply', 'product_to_exclude', 'product_to_buy', 'discount_product', 'purchase_history_products');
325
+ foreach ($get_variants_for as $type){
326
+ $variant_key = $type.'_variants';
327
+ if(isset($request[$type])){
328
+ $products = $request[$type];
329
+ if(is_string($products)){
330
+ $products = json_decode($products, true);
331
+ }
332
+ $request[$variant_key] = array();
333
+ if(!empty($products)){
334
+ $request[$variant_key] = $this->getVariantsOfProducts($products);
335
+ }
336
+ }
337
+ }
338
+
339
+ return $request;
340
+ }
341
+
342
+ /**
343
+ * Get variants of the products selected
344
+ * */
345
+ protected function getVariantsOfProducts($products){
346
+ $variants = array();
347
+ if(!empty($products)){
348
+ foreach ($products as $product_id){
349
+ $product = FlycartWoocommerceProduct::wc_get_product($product_id);
350
+ if(method_exists($product, 'is_type')){
351
+ if($product->is_type(array('variable', 'variable-subscription'))){
352
+ $additional_variants = FlycartWoocommerceProduct::get_children($product);
353
+ if(!empty($additional_variants) && is_array($additional_variants)){
354
+ $variants = array_merge($variants, $additional_variants);
355
+ }
356
+ }
357
+ }
358
+ }
359
+ }
360
+
361
+ return $variants;
362
+ }
363
+
364
 
365
  /**
366
  * For update the last update time of rule
527
  */
528
  public function filterRules()
529
  {
530
+ if(self::$rules_filtered){
531
+ return $this->rules = self::$filtered_rules;
532
+ }
533
  $rules = $this->rules;
534
 
535
  if (is_null($rules) || !isset($rules)) return false;
547
  $validateDate = FlycartWooDiscountRulesGeneralHelper::validateDateAndTime($date_from, $date_to);
548
  // Validating Rule with Date of Expiry.
549
  if ($validateDate) {
 
550
  // Validating the Rule with its Order ID.
551
  if (isset($rule->rule_order)) {
552
+ $load_rule = apply_filters('woo_discount_rules_run_price_rule', true, $rule);
553
+ if($load_rule){
554
+ // If Order ID is '-', then this rule not going to implement.
555
+ if ($rule->rule_order !== '-') {
556
+ $rule_set[] = $rule;
557
+ }
558
  }
559
  }
560
  }
566
 
567
  // To Order the Rules, based on its order ID.
568
  $this->orderRules();
569
+ self::$rules_filtered = 1;
570
+ self::$filtered_rules = $this->rules;
571
  }
572
 
573
  /**
836
  */
837
  public function generateRuleSets($woocommerce)
838
  {
839
+ if(self::$rule_sets_generated){
840
+ return $this->rule_sets = self::$generated_rule_sets;
841
+ }
842
  $rule_sets = array();
843
 
844
  if (!isset($this->rules)) return false;
868
  if ($rule->apply_to == 'specific_products') {
869
  if (isset($rule->product_to_apply)) {
870
  $rule_sets[$index]['type']['specific_products'] = $this->checkWithProducts($rule, $woocommerce);
871
+ $variants = null;
872
+ if(isset($rule->product_to_apply_variants)) $variants = $rule->product_to_apply_variants;
873
+ $rule_sets[$index]['type']['specific_products'] = apply_filters('woo_discount_rule_products_to_include', $rule_sets[$index]['type']['specific_products'], $rule, $variants);
874
  }
875
  if (isset($rule->is_cumulative_for_products) && $rule->is_cumulative_for_products) {
876
  $rule_sets[$index]['is_cumulative_for_products'] = 1;
981
  $rule_sets[$index]['product_based_discount'] = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
982
  }
983
  }
984
+ self::$generated_rule_sets = $this->rule_sets = $rule_sets;
985
+
986
+ self::$rule_sets_generated = 1;
987
  }
988
 
989
  /**
1445
  $quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
1446
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
1447
  $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
1448
+ $variants = null;
1449
+ if(isset($product_based_conditions['product_to_buy_variants'])) $variants = $product_based_conditions['product_to_buy_variants'];
1450
+ $product_to_buy = apply_filters('woo_discount_rule_products_to_include', $product_to_buy, $rule, $variants);
1451
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
1452
  $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
1453
+ $variants = null;
1454
+ if(isset($product_based_conditions['product_to_apply_variants'])) $variants = $product_based_conditions['product_to_apply_variants'];
1455
+ $product_to_apply = apply_filters('woo_discount_rule_products_to_include', $product_to_apply, $rule, $variants);
1456
  $category_to_apply = isset($product_based_conditions['category_to_apply']) ? $product_based_conditions['category_to_apply'] : array();
1457
  $get_discount_type = isset($product_based_conditions['get_discount_type']) ? $product_based_conditions['get_discount_type'] : 'product';
1458
 
1737
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
1738
  $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
1739
  if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'any_cheapest'){
1740
+ $variants = null;
1741
+ if(isset($range->discount_product_variants)) $variants = $range->discount_product_variants;
1742
+ $productIds = apply_filters('woo_discount_rule_products_to_include', $productIds, $discount_ranges, $variants);
1743
  }
1744
  if($discount_product_option == 'same_product'){
1745
  $productId = FlycartWoocommerceProduct::get_id($item['data']);
2481
  if (in_array($id, $products_to_apply)) {
2482
  $status = true;
2483
  }
2484
+ if($product->is_type(array('variable', 'variable-subscription'))){
2485
+ $variations = FlycartWoocommerceProduct::get_variant_ids($product_id);
2486
+ if(!empty($variations)){
2487
+ if (count(array_intersect($variations, $products_to_apply)) > 0) {
2488
+ $status = true;
2489
+ }
2490
  }
2491
  }
2492
  }
2625
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
2626
  if(is_array($children) && count($children)){
2627
  foreach ( $children as $child ) {
2628
+ $is_visible = FlycartWoocommerceProduct::variation_is_visible_in_frontend($child);
2629
+ if ( '' !== FlycartWoocommerceProduct::get_price($child) && $is_visible) {
2630
  $childProducts[] = FlycartWoocommerceProduct::get_id($child);
2631
  }
2632
  }
2700
  if(!is_array($productToExclude)){
2701
  $productToExclude = array();
2702
  }
2703
+ $variants = null;
2704
+ if(isset($rule->product_to_exclude_variants)) $variants = $rule->product_to_exclude_variants;
2705
 
2706
+ $productToExclude = apply_filters('woo_discount_rule_products_to_exclude', $productToExclude, $rule, $variants);
2707
 
2708
  return $productToExclude;
2709
  }
3245
  $currencies = $WOOCS->get_currencies();
3246
  $is_geoip_manipulation = $WOOCS->is_geoip_manipulation;
3247
  $woocs_is_fixed_enabled = $WOOCS->is_fixed_enabled;
3248
+ $woocs_convert_value_based_on_currency = apply_filters('woo_discount_rules_woocs_convert_price_based_on_currency', false, $product);
3249
  //woocs_is_geoip_manipulation //woocs_is_fixed_enabled
3250
+ if($is_geoip_manipulation || $woocs_is_fixed_enabled || $woocs_convert_value_based_on_currency){
3251
  $amount = $amount / $currencies[$WOOCS->current_currency]['rate'];
3252
  }
3253
  }
3483
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3484
  }
3485
  $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
3486
+ if($item_price != (($price_to_display).$product->get_price_suffix($discountPrice))){
3487
+ $item_price = '<span class="cart_price wdr_product_strikeout"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix($discountPrice) . '</ins></span>';
3488
+ }
3489
  $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
3490
  }
3491
  }
3499
  $show_sale_tag_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'show';
3500
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_price_discount_on_product_page']))? $this->baseConfig['show_price_discount_on_product_page']: 'show';
3501
  if($show_sale_tag_on_product_page == 'show_on_any_rules_matches' || ($show_sale_tag_on_product_page == 'show' && $show_price_discount_on_product_page == 'dont')) {
3502
+ $excluded_product_type = apply_filters('woo_discount_rules_exclude_product_type_for_sale_price_strikeout_adjustment', array('variable', 'subscription_variation', 'variable-subscription', 'grouped', 'composite'), $product);
3503
+ if(is_array($excluded_product_type) && !empty($excluded_product_type)){
3504
+ if (!$product->is_type($excluded_product_type)) {
3505
+ $product_id = FlycartWoocommerceProduct::get_id($product);
3506
  // if(!empty(self::$product_on_sale_details[$product_id])){
3507
  $sale_price = FlycartWoocommerceProduct::get_price($product);
3508
  $regular_price = FlycartWoocommerceProduct::get_regular_price($product);
3513
  return $item_price;
3514
  }
3515
  // }
3516
+ }
3517
  }
3518
  }
3519
 
3571
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
3572
  }
3573
  $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
3574
+ if($item_price != (self::$product_has_strike_out[$product_id]['new_strikeout_html'])){
3575
+ $item_price = '<span class="cart_price wdr_product_strikeout"><del>' . $item_price . '</del> <ins>' . (self::$product_has_strike_out[$product_id]['new_strikeout_html']) . '</ins></span>';
3576
+ }
3577
  $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
3578
  }
3579
  } else {
3662
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
3663
  if(is_array($children) && count($children)){
3664
  foreach ( $children as $child ) {
3665
+ $is_visible = FlycartWoocommerceProduct::variation_is_visible_in_frontend($child);
3666
+ if ( '' !== FlycartWoocommerceProduct::get_price($child) && $is_visible) {
3667
  $child_prices[FlycartWoocommerceProduct::get_id($child)] = 'incl' === $tax_display_mode ? FlycartWoocommerceProduct::get_price_including_tax($child) : FlycartWoocommerceProduct::get_price_excluding_tax( $child );
3668
  }
3669
  }
3733
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
3734
  if(is_array($children) && count($children)){
3735
  foreach ( $children as $child ) {
3736
+ $is_visible = FlycartWoocommerceProduct::variation_is_visible_in_frontend($child);
3737
+ if ( '' !== FlycartWoocommerceProduct::get_price($child) && $is_visible) {
3738
  $child_prices[FlycartWoocommerceProduct::get_id($child)] = 'incl' === $tax_display_mode ? FlycartWoocommerceProduct::get_price_including_tax($child) : FlycartWoocommerceProduct::get_price_excluding_tax( $child );
3739
  }
3740
  }
3837
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
3838
  if(is_array($children) && count($children)){
3839
  foreach ( $children as $child ) {
3840
+ $is_visible = FlycartWoocommerceProduct::variation_is_visible_in_frontend($child);
3841
+ if ( '' !== FlycartWoocommerceProduct::get_price($child) && $is_visible) {
3842
  $discountPrice = $this->getDiscountPriceForTheProduct($child);
3843
  if($discountPrice > 0){
3844
  $on_sale = true;
loader.php CHANGED
@@ -34,6 +34,8 @@ if(!class_exists('FlycartWooDiscountRules')){
34
  public $pricingRules;
35
  public $config;
36
 
 
 
37
  /**
38
  * To run the plugin
39
  * */
@@ -390,8 +392,8 @@ if(!class_exists('FlycartWooDiscountRules')){
390
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
391
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForCartRules'));
392
 
393
- add_filter('woo_discount_rule_products_to_exclude', array($this, 'woo_discount_get_variations'));
394
- add_filter('woo_discount_rule_products_to_include', array($this, 'woo_discount_get_variations'));
395
  }
396
 
397
  /**
@@ -400,9 +402,16 @@ if(!class_exists('FlycartWooDiscountRules')){
400
  * @param array $excluded_products
401
  * @return array
402
  * */
403
- public function woo_discount_get_variations($excluded_products = array()) {
404
  $include_variants_on_select_parent_product = $this->discountBase->getConfigData('include_variants_on_select_parent_product', 0);
405
  if($include_variants_on_select_parent_product){
 
 
 
 
 
 
 
406
  static $sets;
407
  if (!is_array($sets)) {
408
  $sets = array();
@@ -414,10 +423,15 @@ if(!class_exists('FlycartWooDiscountRules')){
414
  if (!isset($sets[$string])) {
415
  $all_excluded_products = $excluded_products;
416
  foreach ($excluded_products as $exclude_id) {
417
- $product = wc_get_product($exclude_id);
418
- if (is_object($product) && method_exists($product, 'get_type') && $product->get_type() == 'variable') {
419
- $children_ids = $product->get_children();
420
- $all_excluded_products = array_merge($all_excluded_products, $children_ids);
 
 
 
 
 
421
  }
422
  }
423
  $sets[$string] = $all_excluded_products;
34
  public $pricingRules;
35
  public $config;
36
 
37
+ public static $product_variations = array();
38
+
39
  /**
40
  * To run the plugin
41
  * */
392
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForPriceRules'));
393
  add_action('woocommerce_before_cart', array($this, 'displayAppliedDiscountMessagesForCartRules'));
394
 
395
+ add_filter('woo_discount_rule_products_to_exclude', array($this, 'woo_discount_get_variations'), 3, 10);
396
+ add_filter('woo_discount_rule_products_to_include', array($this, 'woo_discount_get_variations'), 3, 10);
397
  }
398
 
399
  /**
402
  * @param array $excluded_products
403
  * @return array
404
  * */
405
+ public function woo_discount_get_variations($excluded_products = array(), $rule, $variants = null) {
406
  $include_variants_on_select_parent_product = $this->discountBase->getConfigData('include_variants_on_select_parent_product', 0);
407
  if($include_variants_on_select_parent_product){
408
+ // Load from Rules if we already saved with rules
409
+ if($variants !== null && is_array($variants)){
410
+ if(!empty($variants)){
411
+ $excluded_products = array_merge($excluded_products, $variants);
412
+ }
413
+ return $excluded_products;
414
+ }
415
  static $sets;
416
  if (!is_array($sets)) {
417
  $sets = array();
423
  if (!isset($sets[$string])) {
424
  $all_excluded_products = $excluded_products;
425
  foreach ($excluded_products as $exclude_id) {
426
+ if(isset(self::$product_variations[$exclude_id])){} else {
427
+ $product = FlycartWoocommerceProduct::wc_get_product($exclude_id);
428
+ if (is_object($product) && method_exists($product, 'get_type') && $product->get_type() == 'variable') {
429
+ self::$product_variations[$exclude_id] = $children_ids = FlycartWoocommerceProduct::get_children($product);//$product->get_children();
430
+ //$all_excluded_products = array_merge($all_excluded_products, $children_ids);
431
+ }
432
+ }
433
+ if(is_array(self::$product_variations[$exclude_id]) && !empty(self::$product_variations[$exclude_id])){
434
+ $all_excluded_products = array_merge($all_excluded_products, self::$product_variations[$exclude_id]);
435
  }
436
  }
437
  $sets[$string] = $all_excluded_products;
readme.txt CHANGED
@@ -4,14 +4,14 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 5.1
7
- Stable tag: 1.7.12
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
11
  Create simple to complex discount rules, dynamic pricing and discounts for your WooCommerce online store.
12
  == Description ==
13
 
14
- WooCommerce Discount Rules helps you to create any type of bulk discounts, dynamic pricing, advanced discounts, percentage discounts, user role based discounts for your products. Offer Product quantity based discounts, cart based discounts at a percentage or fixed amount or Buy One and Get one free (BOGO) deals or discount based on total order. Increase your sales multifold by offering dynamic pricing and discounts based on categories, products, user roles, cart items, purchase history and much more.
15
 
16
  You can set discounts for products, product variations, categories, attributes and more. You can also create customer specific, user roles based discounts.
17
 
@@ -281,7 +281,7 @@ In that case, the rule with the higher priority will be applied.
281
 
282
  = What happens after my PRO license expires ? =
283
 
284
- You can continue using WooCommerce Discount rules plugin in your site. However you won’t be able to receive the Updates and priority support.
285
 
286
  = What is your refund policy? =
287
 
@@ -312,6 +312,18 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
312
 
313
  == Changelog ==
314
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  = 1.7.12 - 02/04/19 =
316
  * Feature - Option to disable third party coupon while any rule applied.
317
  * Feature - Option to change coupon name in front end.
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 5.1
7
+ Stable tag: 1.7.13
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
11
  Create simple to complex discount rules, dynamic pricing and discounts for your WooCommerce online store.
12
  == Description ==
13
 
14
+ Discount Rules for WooCommerce helps you to create any type of bulk discounts, dynamic pricing, advanced discounts, percentage discounts, user role based discounts for your products. Offer Product quantity based discounts, cart based discounts at a percentage or fixed amount or Buy One and Get one free (BOGO) deals or discount based on total order. Increase your sales multifold by offering dynamic pricing and discounts based on categories, products, user roles, cart items, purchase history and much more.
15
 
16
  You can set discounts for products, product variations, categories, attributes and more. You can also create customer specific, user roles based discounts.
17
 
281
 
282
  = What happens after my PRO license expires ? =
283
 
284
+ You can continue using Discount Rules for WooCommerce plugin in your site. However you won’t be able to receive the Updates and priority support.
285
 
286
  = What is your refund policy? =
287
 
312
 
313
  == Changelog ==
314
 
315
+ = 1.7.13 - 02/05/19 =
316
+ * Improvement - Performance improvement, while having large number of rules with specific product options.
317
+ * Improvement - Consider only visible product variations for displaying strikeout.
318
+ * Improvement - Event apply_filters('woo_discount_rules_exclude_product_type_for_sale_price_strikeout_adjustment', $product_types, $product) - Exclude product type for sale price strikeout adjustment.
319
+ * Improvement - Event apply_filters('woo_discount_rules_load_cart_from_woocommerce_object', true) - To load cart from wc() object or $woocommerce variable.
320
+ * Improvement - Event apply_filters('woo_discount_rules_apply_rules', $status) - Run rules or not.
321
+ * Improvement - Event apply_filters('woo_discount_rules_run_price_rule', true, $rule), apply_filters('woo_discount_rules_run_cart_rule', true, $rule) - Enable/Disable specific rule.
322
+ * Improvement - Event apply_filters('woo_discount_rules_woocs_convert_price_based_on_currency', false, $product) - For Woocommerce currency switcher compatible
323
+ * Fix - Displaying same strike out when product is on sale (option - covered under any price based rule).
324
+ * Fix - Loading default language product when WPML is available on product select box.
325
+ * Fix - Not hiding all zero value of coupon while having multiple coupon based rules.
326
+
327
  = 1.7.12 - 02/04/19 =
328
  * Feature - Option to disable third party coupon while any rule applied.
329
  * Feature - Option to change coupon name in front end.
woo-discount-rules.php CHANGED
@@ -5,13 +5,13 @@
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
- * Version: 1.7.12
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/
12
  * Requires at least: 4.6.1
13
  * WC requires at least: 2.4
14
- * WC tested up to: 3.5
15
  */
16
 
17
  if (!defined('ABSPATH')) exit; // Exit if accessed directly
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.7.13
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/
12
  * Requires at least: 4.6.1
13
  * WC requires at least: 2.4
14
+ * WC tested up to: 3.6
15
  */
16
 
17
  if (!defined('ABSPATH')) exit; // Exit if accessed directly