Discount Rules for WooCommerce - Version 1.6.0

Version Description

  • 08/05/18 =
  • Fix - PHP Warning: in cart rules detail page.
  • Feature - Price rule based on product attribute(Pro)
  • Feature - Price rule based on Subtotal(Pro)
  • Feature - Purchase history option less than amount in price rules(Pro)
  • Feature - Dynamic item count option in BOGO(Pro)
Download this release

Release Info

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

Code changes from version 1.5.11 to 1.6.0

assets/css/style.css CHANGED
@@ -68,7 +68,7 @@
68
  font-size: 13px;
69
  font-style: italic;
70
  }
71
- .coupons_to_apply{
72
  max-width: 250px;
73
  }
74
  .discount_product_option {
@@ -82,4 +82,10 @@
82
  }
83
  .discount_product_percent_con, .price_discount_product_list_con{
84
  margin: 10px 0;
 
 
 
 
 
 
85
  }
68
  font-size: 13px;
69
  font-style: italic;
70
  }
71
+ .coupons_to_apply, .subtotal_to_apply{
72
  max-width: 250px;
73
  }
74
  .discount_product_option {
82
  }
83
  .discount_product_percent_con, .price_discount_product_list_con{
84
  margin: 10px 0;
85
+ }
86
+ #product_attributes_list, #product_list, #cumulative_for_products_cont{
87
+ margin-top: 10px;
88
+ }
89
+ .discount_product_item_count_type {
90
+ width: 170px !important;
91
  }
assets/js/app.js CHANGED
@@ -155,7 +155,12 @@ function trigger_woocommerce_tooltip(){
155
  form += ' <label> Free quantity <span class="woocommerce-help-tip" data-tip="Number of quantity(ies) in each selected product(s)"></span> <input type="text" name="discount_range['+count+'][discount_bogo_qty]" class="form-control" value="" placeholder="ex. 1" /></label>';
156
  form += '</div>';
157
  form += '<div class="discount_product_option_more_cheapest_con hide">';
158
- form += ' <label> Item count <span class="woocommerce-help-tip" data-tip="Discount for number of item(s) in cart"></span><input type="text" name="discount_range['+count+'][discount_product_items]" class="form-control" value="" placeholder="ex. 1" /></label>';
 
 
 
 
 
159
  form += ' <label> Item quantity <span class="woocommerce-help-tip" data-tip="Discount for number of quantity(ies) in each item"></span><input type="text" name="discount_range['+count+'][discount_product_qty]" class="form-control" value="" placeholder="ex. 1" /></label>';
160
  form += '</div>';
161
  form += '<div class="discount_product_option_list_con">';
@@ -280,14 +285,22 @@ function trigger_woocommerce_tooltip(){
280
  if (option == 'specific_products') {
281
  $('#product_list').css('display', 'block');
282
  $('#category_list').css('display', 'none');
 
283
  $('#product_exclude_list').hide();
284
  } else if (option == 'specific_category') {
285
  $('#product_list').css('display', 'none');
 
286
  $('#category_list').css('display', 'block');
287
  $('#product_exclude_list').show();
 
 
 
 
 
288
  } else {
289
  $('#product_list').css('display', 'none');
290
  $('#category_list').css('display', 'none');
 
291
  $('#product_exclude_list').show();
292
  $('#cumulative_for_products_cont').show();
293
  }
@@ -313,6 +326,16 @@ function trigger_woocommerce_tooltip(){
313
  });
314
  $('#coupon_option_price_rule').trigger('change');
315
 
 
 
 
 
 
 
 
 
 
 
316
  $(document).on('keyup', '.rule_descr', function () {
317
  var value = $(this).val();
318
  value = '| ' + value;
@@ -485,6 +508,17 @@ function trigger_woocommerce_tooltip(){
485
  });
486
  $('select.discount_product_option').trigger('change');
487
 
 
 
 
 
 
 
 
 
 
 
 
488
  //on change discount_product_discount_type in product discount
489
  $(document).on('change', 'select.discount_product_discount_type', function () {
490
  var discount_product_percent_field = $(this).closest('.discount_product_percent_con').find('.discount_product_percent_field');
155
  form += ' <label> Free quantity <span class="woocommerce-help-tip" data-tip="Number of quantity(ies) in each selected product(s)"></span> <input type="text" name="discount_range['+count+'][discount_bogo_qty]" class="form-control" value="" placeholder="ex. 1" /></label>';
156
  form += '</div>';
157
  form += '<div class="discount_product_option_more_cheapest_con hide">';
158
+ form += '<select class="selectpicker discount_product_item_count_type" name="discount_range['+count+'][discount_product_item_type]">';
159
+ form += '<option value="static">Fixed item count</option>';
160
+ form += '<option value="dynamic">Dynamic item count</option>';
161
+ form += '</select>';
162
+ form += '<span class="woocommerce-help-tip" data-tip="Fixed item count - You need to provide item count manually<br>Dynamic item count - System will choose dynamically based on cart"></span>';
163
+ form += ' <label class="discount_product_items_count_field"> Item count <span class="woocommerce-help-tip" data-tip="Discount for number of item(s) in cart"></span><input type="text" name="discount_range['+count+'][discount_product_items]" class="form-control discount_product_items_count_field" value="" placeholder="ex. 1" /></label>';
164
  form += ' <label> Item quantity <span class="woocommerce-help-tip" data-tip="Discount for number of quantity(ies) in each item"></span><input type="text" name="discount_range['+count+'][discount_product_qty]" class="form-control" value="" placeholder="ex. 1" /></label>';
165
  form += '</div>';
166
  form += '<div class="discount_product_option_list_con">';
285
  if (option == 'specific_products') {
286
  $('#product_list').css('display', 'block');
287
  $('#category_list').css('display', 'none');
288
+ $('#product_attributes_list').css('display', 'none');
289
  $('#product_exclude_list').hide();
290
  } else if (option == 'specific_category') {
291
  $('#product_list').css('display', 'none');
292
+ $('#product_attributes_list').css('display', 'none');
293
  $('#category_list').css('display', 'block');
294
  $('#product_exclude_list').show();
295
+ } else if (option == 'specific_attribute') {
296
+ $('#product_list').css('display', 'none');
297
+ $('#category_list').css('display', 'none');
298
+ $('#product_attributes_list').css('display', 'block');
299
+ $('#product_exclude_list').show();
300
  } else {
301
  $('#product_list').css('display', 'none');
302
  $('#category_list').css('display', 'none');
303
+ $('#product_attributes_list').css('display', 'none');
304
  $('#product_exclude_list').show();
305
  $('#cumulative_for_products_cont').show();
306
  }
326
  });
327
  $('#coupon_option_price_rule').trigger('change');
328
 
329
+ $('#subtotal_option_price_rule').on('change', function () {
330
+ var option = $(this).val();
331
+ if (option == 'none') {
332
+ $('.subtotal_to_apply_price_rule_con').hide();
333
+ } else {
334
+ $('.subtotal_to_apply_price_rule_con').show();
335
+ }
336
+ });
337
+ $('#subtotal_option_price_rule').trigger('change');
338
+
339
  $(document).on('keyup', '.rule_descr', function () {
340
  var value = $(this).val();
341
  value = '| ' + value;
508
  });
509
  $('select.discount_product_option').trigger('change');
510
 
511
+ $(document).on('change', 'select.discount_product_item_count_type', function () {
512
+ var optionVal = $(this).val();
513
+ var target = $(this).closest('.discount_product_option_more_cheapest_con').find('.discount_product_items_count_field');
514
+ if (optionVal == 'static') {
515
+ target.removeClass('hide');
516
+ } else {
517
+ target.addClass('hide');
518
+ }
519
+ });
520
+ $('select.discount_product_item_count_type').trigger('change');
521
+
522
  //on change discount_product_discount_type in product discount
523
  $(document).on('change', 'select.discount_product_discount_type', function () {
524
  var discount_product_percent_field = $(this).closest('.discount_product_percent_con').find('.discount_product_percent_field');
helper/woo-function.php CHANGED
@@ -29,6 +29,14 @@ if(!class_exists('FlycartWoocommerceVersion')){
29
 
30
  return $data;
31
  }
 
 
 
 
 
 
 
 
32
  }
33
  }
34
 
29
 
30
  return $data;
31
  }
32
+
33
+ /**
34
+ * Is WooCommerce version 3x
35
+ * @return boolean
36
+ * */
37
+ public static function isWCVersion3x(){
38
+ return self::wcVersion('3.0');
39
+ }
40
  }
41
  }
42
 
includes/cart-rules.php CHANGED
@@ -941,7 +941,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
941
  return false;
942
  break;
943
  case 'coupon_applied_any_one':
944
- if(count($rule)){
945
  $ruleSuccess = $this->validateCartCouponAppliedAnyOne($index, $rule, $rules);
946
  if($ruleSuccess){
947
  return true;
@@ -950,7 +950,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
950
  return false;
951
  break;
952
  case 'coupon_applied_all_selected':
953
- if(count($rule)){
954
  $ruleSuccess = $this->validateCartCouponAppliedAllSelected($index, $rule, $rules);
955
  if($ruleSuccess){
956
  return true;
941
  return false;
942
  break;
943
  case 'coupon_applied_any_one':
944
+ if(!empty($rule)){
945
  $ruleSuccess = $this->validateCartCouponAppliedAnyOne($index, $rule, $rules);
946
  if($ruleSuccess){
947
  return true;
950
  return false;
951
  break;
952
  case 'coupon_applied_all_selected':
953
+ if(!empty($rule)){
954
  $ruleSuccess = $this->validateCartCouponAppliedAllSelected($index, $rule, $rules);
955
  if($ruleSuccess){
956
  return true;
includes/pricing-rules.php CHANGED
@@ -148,7 +148,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
148
  'rule_order',
149
  'product_to_exclude',
150
  'coupons_to_apply_option',
151
- 'coupons_to_apply'
 
 
152
  );
153
 
154
  //----------------------------------------------------------------------------------------------------------
@@ -175,6 +177,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
175
 
176
  } elseif ($apply_to == 'specific_products') {
177
  $apply_to = 'product_to_apply';
 
 
178
  }
179
 
180
  if(isset($request['is_cumulative_for_products']) && $request['is_cumulative_for_products'] == 1){
@@ -210,6 +214,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
210
  $form[] = 'based_on_purchase_history';
211
  if($based_on_purchase_history){
212
  $form[] = 'purchased_history_amount';
 
213
  $form[] = 'purchase_history_status_list';
214
  if (isset($request['purchase_history_status_list'])) $request['purchase_history_status_list'] = json_encode($request['purchase_history_status_list']);
215
  else $request['purchase_history_status_list'] = json_encode(array('wc-completed'));
@@ -639,7 +644,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
639
  $rule_sets[$index]['allow']['purchase_history'] = 'yes';
640
  // Default setup for all customers.
641
  $rule_sets[$index]['allow']['users'] = 'all';
642
- $rule_sets[$index]['allow']['user_role'] = true;
643
  $rule_sets[$index]['allow']['coupon'] = 1;
644
 
645
  // For quantity based discount
@@ -671,6 +676,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
671
  $rule_sets[$index]['type']['is_cumulative'] = 0;
672
  }
673
  $rule_sets[$index]['product_to_exclude'] = $this->getExcludeProductsFromRule($rule);
 
 
 
674
  } else {
675
  $rule_sets[$index]['type'] = 'all';
676
  $rule_sets[$index]['product_to_exclude'] = $this->getExcludeProductsFromRule($rule);
@@ -706,6 +714,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
706
  $rule_sets[$index]['allow']['user_role'] = $this->checkWithUserRoles($rule);
707
  }
708
 
 
 
 
 
 
 
 
 
709
  // check for coupon
710
  if(isset($rule->coupons_to_apply_option)){
711
  $rule_sets[$index]['allow']['coupon'] = $this->checkWithCouponApplied($rule);
@@ -713,7 +729,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
713
  }
714
 
715
  // If Current Customer is not Allowed to use this discount, then it's going to be removed.
716
- if ($rule_sets[$index]['allow']['users'] == 'no' || !$rule_sets[$index]['allow']['user_role'] || $rule_sets[$index]['allow']['purchase_history'] == 'no' || !($rule_sets[$index]['allow']['coupon'])) {
717
  unset($rule_sets[$index]);
718
  }
719
 
@@ -758,6 +774,25 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
758
  return $allowed;
759
  }
760
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761
  /**
762
  * check the any one of the selected coupon applied
763
  * */
@@ -803,7 +838,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
803
  $user = get_current_user_id();
804
  if($user){
805
  if(isset($rule->purchased_history_amount) && isset($rule->purchase_history_status_list)){
806
- if($rule->purchased_history_amount > 0){
807
  $purchase_history_status_list = json_decode($rule->purchase_history_status_list, true);
808
  $customerOrders = get_posts( array(
809
  'numberposts' => -1,
@@ -820,9 +855,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
820
  $totalPurchasedAmount += $total;
821
  }
822
  }
823
- if($totalPurchasedAmount >= $rule->purchased_history_amount){
824
- $allowed = 'yes';
 
 
 
 
 
 
 
825
  }
 
826
  }
827
  }
828
  }
@@ -982,6 +1025,16 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
982
  }
983
  }
984
  break;
 
 
 
 
 
 
 
 
 
 
985
 
986
  case 'all_products':
987
  default:
@@ -1303,6 +1356,11 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1303
  * */
1304
  public function getMoreThanOneCheapestProductFromCart($productIds, $discount_quantity = 1, $discount_item = 1, $range){
1305
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'more_than_one_cheapest';
 
 
 
 
 
1306
  $adjustment = array();
1307
  $adjustmentValues = array();
1308
  if($discount_product_option == "more_than_one_cheapest_from_all")
@@ -1321,6 +1379,11 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1321
  $adjustmentValues[$productCheapest['product']] = $productCheapest['percent'];
1322
  $adjustment['product_discount_adjustment'] = $adjustmentValues;
1323
  $adjustment['product_discount_details'][$productCheapest['product']] = $productCheapest['discount_details'];
 
 
 
 
 
1324
  } else {
1325
  break;
1326
  }
@@ -1328,6 +1391,21 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1328
  return $adjustment;
1329
  }
1330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1331
  /**
1332
  * Get all Products from Cart
1333
  * */
@@ -1407,7 +1485,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1407
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$quantity));
1408
  else
1409
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$discount_quantity));
1410
- return array('product' => $cheapestProduct, 'percent' => $discount_price, 'discount_details' => $product_discount_details);
1411
  }
1412
  return array();
1413
  }
@@ -1483,11 +1561,20 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1483
  }
1484
 
1485
  /**
 
1486
  *
 
 
 
1487
  */
1488
- public function isUserInCustomerList()
1489
  {
 
 
 
 
1490
 
 
1491
  }
1492
 
1493
  /**
@@ -1580,6 +1667,22 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1580
  return $specific_category_list;
1581
  }
1582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1583
  /**
1584
  * Check with User list.
1585
  *
@@ -1730,6 +1833,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1730
  $status = true;
1731
  }
1732
  }
 
 
1733
  } else if ($rule->apply_to == 'all_products') {
1734
  $productToExclude = $this->getExcludeProductsFromRule($rule);
1735
  $status = false;
@@ -1745,6 +1850,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1745
  }
1746
  }
1747
 
 
 
 
 
 
 
 
 
 
 
 
1748
  // check for COUPON
1749
  if(isset($rule->coupons_to_apply_option)){
1750
  $statusCoupon = $this->checkWithCouponApplied($rule);
@@ -1925,6 +2041,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1925
  $discount_product_option = isset($value->discount_product_option) ? $value->discount_product_option : 'all';
1926
  $discount_product_discount_type = isset($value->discount_product_discount_type) ? $value->discount_product_discount_type : '';
1927
  $discount_product_percent = isset($value->discount_product_percent) ? $value->discount_product_percent : 0;
 
1928
  $discount_product_items = isset($value->discount_product_items) ? $value->discount_product_items : 1;
1929
  $discount_product_qty = isset($value->discount_product_qty) ? $value->discount_product_qty : 1;
1930
  $product_discount = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_discount);
@@ -1944,10 +2061,15 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1944
  $htmlProduct .= esc_html__('any cheapest one of ', 'woo-discount-rules');
1945
  }
1946
  if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'more_than_one_cheapest_from_all' || $discount_product_option == 'more_than_one_cheapest_from_cat'){
1947
- $htmlProduct .= $discount_product_qty;
1948
- $htmlProduct .= esc_html__(' quantity of any ', 'woo-discount-rules');
1949
- $htmlProduct .= $discount_product_items;
1950
- $htmlProduct .= esc_html__(' cheapest item ', 'woo-discount-rules');
 
 
 
 
 
1951
  }
1952
  if($discount_product_option == 'more_than_one_cheapest_from_cat'){
1953
  $htmlProduct .= esc_html__('from the category ', 'woo-discount-rules');
148
  'rule_order',
149
  'product_to_exclude',
150
  'coupons_to_apply_option',
151
+ 'coupons_to_apply',
152
+ 'subtotal_to_apply_option',
153
+ 'subtotal_to_apply'
154
  );
155
 
156
  //----------------------------------------------------------------------------------------------------------
177
 
178
  } elseif ($apply_to == 'specific_products') {
179
  $apply_to = 'product_to_apply';
180
+ } elseif ($apply_to == 'specific_attribute') {
181
+ $apply_to = 'attribute_to_apply';
182
  }
183
 
184
  if(isset($request['is_cumulative_for_products']) && $request['is_cumulative_for_products'] == 1){
214
  $form[] = 'based_on_purchase_history';
215
  if($based_on_purchase_history){
216
  $form[] = 'purchased_history_amount';
217
+ $form[] = 'purchased_history_type';
218
  $form[] = 'purchase_history_status_list';
219
  if (isset($request['purchase_history_status_list'])) $request['purchase_history_status_list'] = json_encode($request['purchase_history_status_list']);
220
  else $request['purchase_history_status_list'] = json_encode(array('wc-completed'));
644
  $rule_sets[$index]['allow']['purchase_history'] = 'yes';
645
  // Default setup for all customers.
646
  $rule_sets[$index]['allow']['users'] = 'all';
647
+ $rule_sets[$index]['allow']['user_role'] = $rule_sets[$index]['allow']['subtotal'] = true;
648
  $rule_sets[$index]['allow']['coupon'] = 1;
649
 
650
  // For quantity based discount
676
  $rule_sets[$index]['type']['is_cumulative'] = 0;
677
  }
678
  $rule_sets[$index]['product_to_exclude'] = $this->getExcludeProductsFromRule($rule);
679
+ } else if ($rule->apply_to == 'specific_attribute') {
680
+ $rule_sets[$index]['type']['specific_attribute'] = $this->getAttributeFromRule($rule, $woocommerce);
681
+ $rule_sets[$index]['product_to_exclude'] = $this->getExcludeProductsFromRule($rule);
682
  } else {
683
  $rule_sets[$index]['type'] = 'all';
684
  $rule_sets[$index]['product_to_exclude'] = $this->getExcludeProductsFromRule($rule);
714
  $rule_sets[$index]['allow']['user_role'] = $this->checkWithUserRoles($rule);
715
  }
716
 
717
+ // check for subtotal
718
+ if(isset($rule->subtotal_to_apply_option)){
719
+ $is_woocommerce3 = FlycartWoocommerceVersion::isWCVersion3x();
720
+ if($is_woocommerce3){
721
+ $rule_sets[$index]['allow']['subtotal'] = $this->checkSubtotalMatches($rule);
722
+ }
723
+ }
724
+
725
  // check for coupon
726
  if(isset($rule->coupons_to_apply_option)){
727
  $rule_sets[$index]['allow']['coupon'] = $this->checkWithCouponApplied($rule);
729
  }
730
 
731
  // If Current Customer is not Allowed to use this discount, then it's going to be removed.
732
+ if ($rule_sets[$index]['allow']['users'] == 'no' || !$rule_sets[$index]['allow']['user_role'] || $rule_sets[$index]['allow']['purchase_history'] == 'no' || !($rule_sets[$index]['allow']['coupon']) || !($rule_sets[$index]['allow']['subtotal'])) {
733
  unset($rule_sets[$index]);
734
  }
735
 
774
  return $allowed;
775
  }
776
 
777
+ /**
778
+ * Check subtotal matches
779
+ * */
780
+ public function checkSubtotalMatches($rule){
781
+ $allowed = 1;
782
+ if(isset($rule->subtotal_to_apply_option)){
783
+ if($rule->subtotal_to_apply_option == 'atleast'){
784
+ if(isset($rule->subtotal_to_apply) && $rule->subtotal_to_apply > 0){
785
+ $sub_total = FlycartWooDiscountRulesAdvancedHelper::get_calculated_item_subtotal();
786
+ if(!($rule->subtotal_to_apply <= $sub_total)){
787
+ $allowed = 0;
788
+ }
789
+ }
790
+ }
791
+ }
792
+
793
+ return $allowed;
794
+ }
795
+
796
  /**
797
  * check the any one of the selected coupon applied
798
  * */
838
  $user = get_current_user_id();
839
  if($user){
840
  if(isset($rule->purchased_history_amount) && isset($rule->purchase_history_status_list)){
841
+ if($rule->purchased_history_amount >= 0){
842
  $purchase_history_status_list = json_decode($rule->purchase_history_status_list, true);
843
  $customerOrders = get_posts( array(
844
  'numberposts' => -1,
855
  $totalPurchasedAmount += $total;
856
  }
857
  }
858
+ $purchased_history_type = isset($rule->purchased_history_type)? $rule->purchased_history_type: 'atleast';
859
+ if($purchased_history_type == 'less_than_or_equal'){
860
+ if($totalPurchasedAmount <= $rule->purchased_history_amount){
861
+ $allowed = 'yes';
862
+ }
863
+ } else {
864
+ if($totalPurchasedAmount >= $rule->purchased_history_amount){
865
+ $allowed = 'yes';
866
+ }
867
  }
868
+
869
  }
870
  }
871
  }
1025
  }
1026
  }
1027
  break;
1028
+ case 'specific_attribute':
1029
+ $notInProductList = !$this->isItemInProductList($rule['product_to_exclude'], $item);
1030
+ if ($this->isItemInAttributeList($rule['type']['specific_attribute'], $item) && $notInProductList) {
1031
+ $alreadyExists = 0;
1032
+ if(!$alreadyExists){
1033
+ $discount_amount = $this->getAdjustmentAmount($item, $quantity, $this->array_first($rule['discount']), $product_page, $bogo);
1034
+ $applied_rules[$i] = $this->formatRulesToApply($discount_amount, $rule['name'], $index, $item['product_id'], $id);
1035
+ }
1036
+ }
1037
+ break;
1038
 
1039
  case 'all_products':
1040
  default:
1356
  * */
1357
  public function getMoreThanOneCheapestProductFromCart($productIds, $discount_quantity = 1, $discount_item = 1, $range){
1358
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'more_than_one_cheapest';
1359
+ $discount_product_item_type = isset($range->discount_product_item_type) ? $range->discount_product_item_type : 'static';
1360
+ if($discount_product_item_type == 'dynamic'){
1361
+ $cart_item_details = $this->getTotalQuantitiesAndItems();
1362
+ if(!empty($cart_item_details['total_items'])) $discount_item = $cart_item_details['total_items'];
1363
+ }
1364
  $adjustment = array();
1365
  $adjustmentValues = array();
1366
  if($discount_product_option == "more_than_one_cheapest_from_all")
1379
  $adjustmentValues[$productCheapest['product']] = $productCheapest['percent'];
1380
  $adjustment['product_discount_adjustment'] = $adjustmentValues;
1381
  $adjustment['product_discount_details'][$productCheapest['product']] = $productCheapest['discount_details'];
1382
+ if($discount_product_item_type == 'dynamic'){
1383
+ $applied_quantity = $productCheapest['applied_quantity'];
1384
+ if($applied_quantity) $discount_quantity -= $applied_quantity;
1385
+ if($discount_quantity <= 0) break;
1386
+ }
1387
  } else {
1388
  break;
1389
  }
1391
  return $adjustment;
1392
  }
1393
 
1394
+ /**
1395
+ * Get total quantities and items from Cart
1396
+ * */
1397
+ protected function getTotalQuantitiesAndItems(){
1398
+ $cart_item_details = array();
1399
+ $cart_item_details['total_items'] = $cart_item_details['total_quantities'] = 0;
1400
+ $cart = FlycartWoocommerceCart::get_cart();
1401
+ foreach ( $cart as $cart_item ) {
1402
+ $cart_item_details['total_items']++;
1403
+ $cart_item_details['total_quantities'] += $cart_item['quantity'];
1404
+ }
1405
+
1406
+ return $cart_item_details;
1407
+ }
1408
+
1409
  /**
1410
  * Get all Products from Cart
1411
  * */
1485
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$quantity));
1486
  else
1487
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$discount_quantity));
1488
+ return array('product' => $cheapestProduct, 'percent' => $discount_price, 'discount_details' => $product_discount_details, 'applied_quantity' => $quantity);
1489
  }
1490
  return array();
1491
  }
1561
  }
1562
 
1563
  /**
1564
+ * To Check that the items are in specified attribute.
1565
  *
1566
+ * @param $attribute_list
1567
+ * @param $product
1568
+ * @return bool
1569
  */
1570
+ public function isItemInAttributeList($attribute_list, $product)
1571
  {
1572
+ if (!isset($product['variation_id']) || !$product['variation_id'] ) return false;
1573
+ if (!isset($product['variation']) || empty($product['variation']) ) return false;
1574
+ if(empty($attribute_list)) return false;
1575
+ $status = FlycartWooDiscountRulesAdvancedHelper::validateCartItemInSelectedAttributes($product['variation'], $attribute_list);
1576
 
1577
+ return $status;
1578
  }
1579
 
1580
  /**
1667
  return $specific_category_list;
1668
  }
1669
 
1670
+ /**
1671
+ * Check with attribute list.
1672
+ *
1673
+ * @param $rule
1674
+ * @param $woocommerce
1675
+ * @return array|mixed
1676
+ */
1677
+ public function getAttributeFromRule($rule, $woocommerce)
1678
+ {
1679
+ $specific_attribute_list = array();
1680
+ if (is_string($rule->attribute_to_apply)) {
1681
+ $specific_attribute_list = json_decode($rule->attribute_to_apply, true);
1682
+ }
1683
+ return $specific_attribute_list;
1684
+ }
1685
+
1686
  /**
1687
  * Check with User list.
1688
  *
1833
  $status = true;
1834
  }
1835
  }
1836
+ } elseif ($rule->apply_to == 'specific_attribute') {
1837
+ $status = false;
1838
  } else if ($rule->apply_to == 'all_products') {
1839
  $productToExclude = $this->getExcludeProductsFromRule($rule);
1840
  $status = false;
1850
  }
1851
  }
1852
 
1853
+ // check for subtotal
1854
+ if(isset($rule->subtotal_to_apply_option)){
1855
+ $is_woocommerce3 = FlycartWoocommerceVersion::isWCVersion3x();
1856
+ if($is_woocommerce3){
1857
+ $subtotalStatus = $this->checkSubtotalMatches($rule);
1858
+ if(!$subtotalStatus){
1859
+ $status = false;
1860
+ }
1861
+ }
1862
+ }
1863
+
1864
  // check for COUPON
1865
  if(isset($rule->coupons_to_apply_option)){
1866
  $statusCoupon = $this->checkWithCouponApplied($rule);
2041
  $discount_product_option = isset($value->discount_product_option) ? $value->discount_product_option : 'all';
2042
  $discount_product_discount_type = isset($value->discount_product_discount_type) ? $value->discount_product_discount_type : '';
2043
  $discount_product_percent = isset($value->discount_product_percent) ? $value->discount_product_percent : 0;
2044
+ $discount_product_item_type = isset($value->discount_product_item_type) ? $value->discount_product_item_type : 'static';
2045
  $discount_product_items = isset($value->discount_product_items) ? $value->discount_product_items : 1;
2046
  $discount_product_qty = isset($value->discount_product_qty) ? $value->discount_product_qty : 1;
2047
  $product_discount = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_discount);
2061
  $htmlProduct .= esc_html__('any cheapest one of ', 'woo-discount-rules');
2062
  }
2063
  if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'more_than_one_cheapest_from_all' || $discount_product_option == 'more_than_one_cheapest_from_cat'){
2064
+ if($discount_product_item_type == 'static'){
2065
+ $htmlProduct .= $discount_product_qty;
2066
+ $htmlProduct .= esc_html__(' quantity of any ', 'woo-discount-rules');
2067
+ $htmlProduct .= $discount_product_items;
2068
+ $htmlProduct .= esc_html__(' cheapest item ', 'woo-discount-rules');
2069
+ } else {
2070
+ $htmlProduct .= $discount_product_qty;
2071
+ $htmlProduct .= esc_html__(' quantity of cheapest item ', 'woo-discount-rules');
2072
+ }
2073
  }
2074
  if($discount_product_option == 'more_than_one_cheapest_from_cat'){
2075
  $htmlProduct .= esc_html__('from the category ', 'woo-discount-rules');
loader.php CHANGED
@@ -211,5 +211,7 @@ if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
211
  if($purchase_helper->isPro()){
212
  include_once('includes/advanced/free_shipping_method.php');
213
  include_once('includes/advanced/pricing-productdependent.php');
 
 
214
  }
215
  }
211
  if($purchase_helper->isPro()){
212
  include_once('includes/advanced/free_shipping_method.php');
213
  include_once('includes/advanced/pricing-productdependent.php');
214
+ include_once('includes/advanced/cart-totals.php');
215
+ include_once('includes/advanced/advanced-helper.php');
216
  }
217
  }
readme.txt CHANGED
@@ -1,19 +1,19 @@
1
  === WooCommerce Discount Rules ===
2
  Contributors: flycart
3
  Donate link: https://flycart.org/
4
- Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
- Stable tag: 1.5.11
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 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. Increase your sales multifold by offering dynamic pricing and discounts based on categories, products, user roles, cart items and much more.
15
 
16
- You can set discounts for product and also for each product variation. You can also create customer specific, user roles based discounts.
17
 
18
  Discounts will be visible in product page, product details page, cart, checkout and in email notifications.
19
 
@@ -34,6 +34,7 @@ Display the pricing discount table beautifully on the product page. Start sellin
34
  * Dependant product based discounts (Buy Product A and get discount on Product B) - PRO feature
35
  * Coupons based discount rules (The discount will apply after a coupon is entered.)
36
  * Option to set discount for each product variant. - PRO feature
 
37
  * Option to set Discount for All Products or Global Discount
38
  * Discount for customers with specific domains (10% discount for all emails ending with @acme.com)
39
  * Display or hide the Discount table in Product Page
@@ -243,6 +244,13 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
243
 
244
  == Changelog ==
245
 
 
 
 
 
 
 
 
246
  = 1.5.11 - 02/05/18 =
247
  * Improvement - Multiple strikeout price of an item in cart based on quantity for BOGO price rule
248
  * Improvement - UI improvement
1
  === WooCommerce Discount Rules ===
2
  Contributors: flycart
3
  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: 4.9
7
+ Stable tag: 1.6.0
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 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. Increase your sales multifold by offering dynamic pricing and discounts based on categories, products, user roles, cart items and much more.
15
 
16
+ You can set discounts for product and also for each product variation or attributes. You can also create customer specific, user roles based discounts.
17
 
18
  Discounts will be visible in product page, product details page, cart, checkout and in email notifications.
19
 
34
  * Dependant product based discounts (Buy Product A and get discount on Product B) - PRO feature
35
  * Coupons based discount rules (The discount will apply after a coupon is entered.)
36
  * Option to set discount for each product variant. - PRO feature
37
+ * Attribute specific discount (Buy Small size T-shirts and get 10% discount) - PRO feature
38
  * Option to set Discount for All Products or Global Discount
39
  * Discount for customers with specific domains (10% discount for all emails ending with @acme.com)
40
  * Display or hide the Discount table in Product Page
244
 
245
  == Changelog ==
246
 
247
+ = 1.6.0 - 08/05/18 =
248
+ * Fix - PHP Warning: in cart rules detail page.
249
+ * Feature - Price rule based on product attribute(Pro)
250
+ * Feature - Price rule based on Subtotal(Pro)
251
+ * Feature - Purchase history option less than amount in price rules(Pro)
252
+ * Feature - Dynamic item count option in BOGO(Pro)
253
+
254
  = 1.5.11 - 02/05/18 =
255
  * Improvement - Multiple strikeout price of an item in cart based on quantity for BOGO price rule
256
  * Improvement - UI improvement
view/view-cart-rules.php CHANGED
@@ -326,7 +326,6 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
326
  $class = 'style="display:block"';
327
  $hit = true;
328
  }
329
- //
330
  ?>
331
  <div id="user_div_<?php echo $i; ?>" <?php echo $class; ?>>
332
  <?php
@@ -334,27 +333,6 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
334
  ?>
335
  </div>
336
  <?php
337
- $products_list = array();
338
- $class = 'style="display:none"';
339
- if ($type == 'products_atleast_one' || $type == 'products_not_in') {
340
- $products_list = $discount_rules[$type];;
341
- $class = 'style="display:block"';
342
- $hit = true;
343
- }
344
-
345
- ?>
346
- <div id="product_div_<?php echo $i; ?>" <?php echo $class; ?>>
347
- <select class="product_list selectpicker"
348
- id="cart_product_list_<?php echo $i; ?>"
349
- multiple
350
- name="discount_rule[<?php echo $i; ?>][product_to_apply][]">
351
- <?php foreach ($products as $index => $product) { ?>
352
- <option
353
- value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $product; ?></option>
354
- <?php } ?>
355
- </select>
356
- </div>
357
- <?php
358
  $category_list = array();
359
  $class = 'style="display:none"';
360
  if ($type == 'categories_atleast_one' || $type == 'categories_not_in' || $type == 'categories_in') {
@@ -363,7 +341,6 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
363
  $class = 'style="display:block"';
364
  $hit = true;
365
  }
366
-
367
  ?>
368
  <div id="category_div_<?php echo $i; ?>" <?php echo $class; ?>>
369
  <select class="category_list selectpicker"
@@ -383,9 +360,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
383
  $roles_list = $discount_rules[$type];
384
  $class = 'style="display:block"';
385
  $hit = true;
386
- }
387
-
388
- ?>
389
  <div id="roles_div_<?php echo $i; ?>" <?php echo $class; ?>>
390
  <select class="roles_list selectpicker"
391
  id="cart_roles_list_<?php echo $i; ?>" multiple
@@ -403,9 +378,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
403
  $countries_list = $discount_rules[$type];
404
  $class = 'style="display:block"';
405
  $hit = true;
406
- }
407
-
408
- ?>
409
  <div id="countries_div_<?php echo $i; ?>" <?php echo $class; ?>>
410
  <select class="country_list selectpicker"
411
  data-live-search="true"
@@ -432,9 +405,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
432
  }
433
  $class = 'style="display:block"';
434
  $hit = true;
435
- }
436
-
437
- ?>
438
  <div id="purchase_history_div_<?php echo $i; ?>" <?php echo $class; ?>>
439
  Total purchased amount at least
440
  <input name="discount_rule[<?php echo $i; ?>][purchased_history_amount]" value="<?php echo $purchased_history_amount; ?>" type="text"/> In Order status
326
  $class = 'style="display:block"';
327
  $hit = true;
328
  }
 
329
  ?>
330
  <div id="user_div_<?php echo $i; ?>" <?php echo $class; ?>>
331
  <?php
333
  ?>
334
  </div>
335
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  $category_list = array();
337
  $class = 'style="display:none"';
338
  if ($type == 'categories_atleast_one' || $type == 'categories_not_in' || $type == 'categories_in') {
341
  $class = 'style="display:block"';
342
  $hit = true;
343
  }
 
344
  ?>
345
  <div id="category_div_<?php echo $i; ?>" <?php echo $class; ?>>
346
  <select class="category_list selectpicker"
360
  $roles_list = $discount_rules[$type];
361
  $class = 'style="display:block"';
362
  $hit = true;
363
+ } ?>
 
 
364
  <div id="roles_div_<?php echo $i; ?>" <?php echo $class; ?>>
365
  <select class="roles_list selectpicker"
366
  id="cart_roles_list_<?php echo $i; ?>" multiple
378
  $countries_list = $discount_rules[$type];
379
  $class = 'style="display:block"';
380
  $hit = true;
381
+ } ?>
 
 
382
  <div id="countries_div_<?php echo $i; ?>" <?php echo $class; ?>>
383
  <select class="country_list selectpicker"
384
  data-live-search="true"
405
  }
406
  $class = 'style="display:block"';
407
  $hit = true;
408
+ } ?>
 
 
409
  <div id="purchase_history_div_<?php echo $i; ?>" <?php echo $class; ?>>
410
  Total purchased amount at least
411
  <input name="discount_rule[<?php echo $i; ?>][purchased_history_amount]" value="<?php echo $purchased_history_amount; ?>" type="text"/> In Order status
view/view-pricing-rules.php CHANGED
@@ -21,6 +21,10 @@ $data = $config;
21
  $rule_id = (isset($data->ID)) ? $data->ID : 0;
22
 
23
  $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
 
 
 
 
24
  ?>
25
  <div class="container-fluid">
26
  <form id="form_price_rule">
@@ -133,24 +137,33 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
133
  <div class="row">
134
  <div class="col-md-3"><label> Apply To </label></div>
135
  <?php $opt = (isset($data->apply_to) ? $data->apply_to : ''); ?>
136
- <div class="col-md-6"><select class="selectpicker"
137
  name="apply_to" id="apply_to">
138
  <option
139
  value="all_products" <?php if ($opt == 'all_products') { ?> selected=selected <?php } ?>>
140
- All Products
 
 
 
 
141
  </option>
142
  <option
143
  <?php if (!$pro) { ?> disabled <?php } else { ?> value="specific_category" <?php }
144
  if ($opt == 'specific_category') { ?> selected=selected <?php } ?>>
145
  <?php if (!$pro) { ?>
146
- Specific Categories <b><?php echo $suffix; ?></b>
147
  <?php } else { ?>
148
- Specific Categories
149
  <?php } ?>
150
  </option>
151
  <option
152
- value="specific_products" <?php if ($opt == 'specific_products') { ?> selected=selected <?php } ?>>
153
- Specific Products
 
 
 
 
 
154
  </option>
155
  </select>
156
  <div class="form-group" id="product_list">
@@ -178,6 +191,16 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
178
  <input type="checkbox" name="apply_child_categories" id="apply_child_categories" value="1" <?php if($apply_child_categories) { echo "checked"; } ?>> <label class="checkbox_label" for="apply_child_categories">Check this box to apply child category(ies)</label>
179
  </div>
180
  </div>
 
 
 
 
 
 
 
 
 
 
181
  </div>
182
  </div>
183
  </div>
@@ -185,7 +208,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
185
  <div class="form-group" id="product_exclude_list">
186
  <div class="row">
187
  <div class="col-md-3"><label><?php esc_html_e('Exclude products', 'woo-discount-rules'); ?></label></div>
188
- <div class="col-md-6">
189
  <?php
190
  if(isset($data->product_to_exclude)){
191
  if(is_array($data->product_to_exclude))
@@ -206,7 +229,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
206
  <div class="row">
207
  <div class="col-md-3"><label> Customers </label></div>
208
  <?php $opt = (isset($data->customer) ? $data->customer : ''); ?>
209
- <div class="col-md-6"><select class="selectpicker"
210
  name="customer" id="apply_customer">
211
  <option value="all" <?php if ($opt == 'all') { ?> selected=selected <?php } ?>>
212
  All
@@ -233,7 +256,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
233
  <div class="form-group">
234
  <div class="row">
235
  <div class="col-md-3"><label> <?php esc_html_e('User roles', 'woo-discount-rules') ?> </label></div>
236
- <div class="col-md-6">
237
  <?php
238
  if($pro){
239
  $roles_list = json_decode((isset($data->user_roles_to_apply) ? $data->user_roles_to_apply : '{}'), true); ?>
@@ -259,7 +282,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
259
  <div class="form-group">
260
  <div class="row">
261
  <div class="col-md-3"><label> <?php esc_html_e('Coupon', 'woo-discount-rules') ?> </label></div>
262
- <div class="col-md-6">
263
  <?php
264
  if($pro){
265
  $coupons_to_apply_option = isset($data->coupons_to_apply_option) ? $data->coupons_to_apply_option : 'none';
@@ -292,11 +315,57 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
292
  </div>
293
  </div>
294
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  <div class="form-group">
296
  <div class="row">
297
  <div class="col-md-3"><label><?php esc_html_e('Purchase History', 'woo-discount-rules'); ?></label></div>
298
  <?php $based_on_purchase_history = (isset($data->based_on_purchase_history) ? $data->based_on_purchase_history : 0); ?>
299
- <div class="col-md-6">
300
  <?php
301
  if($pro){
302
  ?>
@@ -315,8 +384,15 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
315
  }
316
  ?>
317
  <div class="form-group" id="based_on_purchase_history_fields">
318
- <?php $purchased_history_amount = (isset($data->purchased_history_amount) ? $data->purchased_history_amount : 0); ?>
319
- <label><?php esc_html_e('Total purchased amount at least', 'woo-discount-rules'); ?></label>
 
 
 
 
 
 
 
320
  <input type="text" value="<?php echo $purchased_history_amount; ?>" name="purchased_history_amount"/>
321
  <label><?php esc_html_e('In Order status', 'woo-discount-rules'); ?></label>
322
  <?php
@@ -493,10 +569,18 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
493
  </label>
494
  </div>
495
  <div class="discount_product_option_more_cheapest_con hide">
496
- <label>Item count <span class="woocommerce-help-tip" data-tip="Discount for number of item(s) in cart"></span>
 
 
 
 
 
 
 
 
497
  <input type="text"
498
  name="discount_range[<?php echo $fieldIndex; ?>][discount_product_items]"
499
- class="form-control"
500
  value="<?php echo(isset($discount->discount_product_items) ? $discount->discount_product_items : ''); ?>"
501
  placeholder="ex. 1" />
502
  </label>
21
  $rule_id = (isset($data->ID)) ? $data->ID : 0;
22
 
23
  $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
24
+ $attributes = array();
25
+ if($isPro){
26
+ $attributes = FlycartWooDiscountRulesAdvancedHelper::get_all_product_attributes();
27
+ }
28
  ?>
29
  <div class="container-fluid">
30
  <form id="form_price_rule">
137
  <div class="row">
138
  <div class="col-md-3"><label> Apply To </label></div>
139
  <?php $opt = (isset($data->apply_to) ? $data->apply_to : ''); ?>
140
+ <div class="col-md-9"><select class="selectpicker"
141
  name="apply_to" id="apply_to">
142
  <option
143
  value="all_products" <?php if ($opt == 'all_products') { ?> selected=selected <?php } ?>>
144
+ All products
145
+ </option>
146
+ <option
147
+ value="specific_products" <?php if ($opt == 'specific_products') { ?> selected=selected <?php } ?>>
148
+ Specific products
149
  </option>
150
  <option
151
  <?php if (!$pro) { ?> disabled <?php } else { ?> value="specific_category" <?php }
152
  if ($opt == 'specific_category') { ?> selected=selected <?php } ?>>
153
  <?php if (!$pro) { ?>
154
+ Specific categories <b><?php echo $suffix; ?></b>
155
  <?php } else { ?>
156
+ Specific categories
157
  <?php } ?>
158
  </option>
159
  <option
160
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="specific_attribute" <?php }
161
+ if ($opt == 'specific_attribute') { ?> selected=selected <?php } ?>>
162
+ <?php if (!$pro) { ?>
163
+ Specific attributes <b><?php echo $suffix; ?></b>
164
+ <?php } else { ?>
165
+ Specific attributes
166
+ <?php } ?>
167
  </option>
168
  </select>
169
  <div class="form-group" id="product_list">
191
  <input type="checkbox" name="apply_child_categories" id="apply_child_categories" value="1" <?php if($apply_child_categories) { echo "checked"; } ?>> <label class="checkbox_label" for="apply_child_categories">Check this box to apply child category(ies)</label>
192
  </div>
193
  </div>
194
+ <div class="form-group" id="product_attributes_list">
195
+ <?php $attribute_list = json_decode((isset($data->attribute_to_apply) ? $data->attribute_to_apply : '{}'), true); ?>
196
+ <select class="attribute_list selectpicker" multiple
197
+ name="attribute_to_apply[]">
198
+ <?php foreach ($attributes as $index => $value) { ?>
199
+ <option
200
+ value="<?php echo $value['id']; ?>"<?php if (in_array($value['id'], $attribute_list)) { ?> selected=selected <?php } ?>><?php echo $value['text']; ?></option>
201
+ <?php } ?>
202
+ </select>
203
+ </div>
204
  </div>
205
  </div>
206
  </div>
208
  <div class="form-group" id="product_exclude_list">
209
  <div class="row">
210
  <div class="col-md-3"><label><?php esc_html_e('Exclude products', 'woo-discount-rules'); ?></label></div>
211
+ <div class="col-md-9">
212
  <?php
213
  if(isset($data->product_to_exclude)){
214
  if(is_array($data->product_to_exclude))
229
  <div class="row">
230
  <div class="col-md-3"><label> Customers </label></div>
231
  <?php $opt = (isset($data->customer) ? $data->customer : ''); ?>
232
+ <div class="col-md-9"><select class="selectpicker"
233
  name="customer" id="apply_customer">
234
  <option value="all" <?php if ($opt == 'all') { ?> selected=selected <?php } ?>>
235
  All
256
  <div class="form-group">
257
  <div class="row">
258
  <div class="col-md-3"><label> <?php esc_html_e('User roles', 'woo-discount-rules') ?> </label></div>
259
+ <div class="col-md-9">
260
  <?php
261
  if($pro){
262
  $roles_list = json_decode((isset($data->user_roles_to_apply) ? $data->user_roles_to_apply : '{}'), true); ?>
282
  <div class="form-group">
283
  <div class="row">
284
  <div class="col-md-3"><label> <?php esc_html_e('Coupon', 'woo-discount-rules') ?> </label></div>
285
+ <div class="col-md-9">
286
  <?php
287
  if($pro){
288
  $coupons_to_apply_option = isset($data->coupons_to_apply_option) ? $data->coupons_to_apply_option : 'none';
315
  </div>
316
  </div>
317
  </div>
318
+ <div class="form-group">
319
+ <div class="row">
320
+ <div class="col-md-3"><label> <?php esc_html_e('Subtotal', 'woo-discount-rules') ?> </label></div>
321
+ <div class="col-md-9">
322
+ <?php
323
+ if($pro){
324
+ $woocommerce3 = FlycartWoocommerceVersion::isWCVersion3x();
325
+ if($woocommerce3){
326
+ $subtotal_to_apply_option = isset($data->subtotal_to_apply_option) ? $data->subtotal_to_apply_option : 'none';
327
+ $subtotal_to_apply = isset($data->subtotal_to_apply) ? $data->subtotal_to_apply : '';
328
+ ?>
329
+ <select class="selectpicker" id="subtotal_option_price_rule" name="subtotal_to_apply_option">
330
+ <option value="none"<?php if ($subtotal_to_apply_option == 'none') { ?> selected=selected <?php } ?>><?php esc_html_e('Do not use', 'woo-discount-rules'); ?></option>
331
+ <option value="atleast"<?php if ($subtotal_to_apply_option == 'atleast') { ?> selected=selected <?php } ?>><?php esc_html_e('Subtotal atleast', 'woo-discount-rules'); ?></option>
332
+ </select>
333
+ <div class="subtotal_to_apply_price_rule_con">
334
+ <span class="woo-discount-hint">
335
+ <?php
336
+ esc_html_e('Enter the amount', 'woo-discount-rules');
337
+ ?>
338
+ </span>
339
+ <input class="form-control subtotal_to_apply" id="subtotal_to_apply" name="subtotal_to_apply" value="<?php echo $subtotal_to_apply; ?>"/>
340
+ </div>
341
+ <?php
342
+ } else {
343
+ ?>
344
+ <div class="woo-support-in_pro">
345
+ <?php
346
+ esc_html_e('Supported in WooCommerce 3.x', 'woo-discount-rules');
347
+ ?>
348
+ </div>
349
+ <?php
350
+ }
351
+ } else {
352
+ ?>
353
+ <div class="woo-support-in_pro">
354
+ <?php
355
+ esc_html_e('Supported in PRO version', 'woo-discount-rules');
356
+ ?>
357
+ </div>
358
+ <?php
359
+ }
360
+ ?>
361
+ </div>
362
+ </div>
363
+ </div>
364
  <div class="form-group">
365
  <div class="row">
366
  <div class="col-md-3"><label><?php esc_html_e('Purchase History', 'woo-discount-rules'); ?></label></div>
367
  <?php $based_on_purchase_history = (isset($data->based_on_purchase_history) ? $data->based_on_purchase_history : 0); ?>
368
+ <div class="col-md-9">
369
  <?php
370
  if($pro){
371
  ?>
384
  }
385
  ?>
386
  <div class="form-group" id="based_on_purchase_history_fields">
387
+ <?php
388
+ $purchased_history_amount = (isset($data->purchased_history_amount) ? $data->purchased_history_amount : 0);
389
+ $purchased_history_type = (isset($data->purchased_history_type) ? $data->purchased_history_type : 'atleast');
390
+ ?>
391
+ <label><?php esc_html_e('Total purchased amount ', 'woo-discount-rules'); ?></label>
392
+ <select class="selectpicker purchased_history_type" name="purchased_history_type">
393
+ <option value="atleast"<?php echo ($purchased_history_type == 'atleast')? ' selected="selected"': ''; ?>><?php esc_html_e('Greater than or equal to', 'woo-discount-rules'); ?></option>
394
+ <option value="less_than_or_equal"<?php echo ($purchased_history_type == 'less_than_or_equal')? ' selected="selected"': ''; ?>><?php esc_html_e('Less than or equal to', 'woo-discount-rules'); ?></option>
395
+ </select>
396
  <input type="text" value="<?php echo $purchased_history_amount; ?>" name="purchased_history_amount"/>
397
  <label><?php esc_html_e('In Order status', 'woo-discount-rules'); ?></label>
398
  <?php
569
  </label>
570
  </div>
571
  <div class="discount_product_option_more_cheapest_con hide">
572
+ <?php
573
+ $discount_product_item_type = (isset($discount->discount_product_item_type) ? $discount->discount_product_item_type : 'static');
574
+ ?>
575
+ <select class="selectpicker discount_product_item_count_type" name="discount_range[<?php echo $fieldIndex; ?>][discount_product_item_type]">
576
+ <option value="static"<?php echo ($discount_product_item_type == 'static')? ' selected="selected"': '' ?>><?php esc_html_e('Fixed item count', 'woo-discount-rules') ?></option>
577
+ <option value="dynamic"<?php echo ($discount_product_item_type == 'dynamic')? ' selected="selected"': '' ?>><?php esc_html_e('Dynamic item count', 'woo-discount-rules') ?></option>
578
+ </select>
579
+ <span class="woocommerce-help-tip" data-tip="Fixed item count - You need to provide item count manually<br>Dynamic item count - System will choose dynamically based on cart"></span>
580
+ <label class="discount_product_items_count_field">Item count <span class="woocommerce-help-tip" data-tip="Discount for number of item(s) in cart"></span>
581
  <input type="text"
582
  name="discount_range[<?php echo $fieldIndex; ?>][discount_product_items]"
583
+ class="form-control discount_product_items_count_field"
584
  value="<?php echo(isset($discount->discount_product_items) ? $discount->discount_product_items : ''); ?>"
585
  placeholder="ex. 1" />
586
  </label>
woo-discount-rules.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
- * Version: 1.5.11
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.6.0
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1