Discount Rules for WooCommerce - Version 1.4.1

Version Description

  • 12/01/17 =
  • Fix - saving price range in price rule condition
Download this release

Release Info

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

Code changes from version 1.4 to 1.4.1

assets/js/app.js CHANGED
@@ -94,7 +94,6 @@ jQuery.noConflict();
94
  '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
95
  }
96
  $('#discount_rule_list').append(form);
97
- $('#discount_rule_list').append(form);
98
  });
99
 
100
  // Removing Discount Rule.
94
  '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
95
  }
96
  $('#discount_rule_list').append(form);
 
97
  });
98
 
99
  // Removing Discount Rule.
includes/pricing-rules.php CHANGED
@@ -478,7 +478,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
478
  case 'specific_products':
479
 
480
  if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
481
- $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, (object)$this->array_first($rule['discount']));
482
  $applied_rules[$i]['name'] = $rule['name'];
483
  $applied_rules[$i]['item'] = $index;
484
  $applied_rules[$i]['id'] = $item['product_id'];
@@ -488,7 +488,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
488
 
489
  case 'specific_category':
490
  if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
491
- $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, (object)$this->array_first($rule['discount']));
492
  $applied_rules[$i]['name'] = $rule['name'];
493
  $applied_rules[$i]['item'] = $index;
494
  $applied_rules[$i]['id'] = $item['product_id'];
@@ -500,7 +500,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
500
  case 'all_products':
501
  default:
502
 
503
- $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, (object)$this->array_first($rule['discount']));
504
  $applied_rules[$i]['name'] = $rule['name'];
505
  $applied_rules[$i]['item'] = $index;
506
  $applied_rules[$i]['id'] = $item['product_id'];
@@ -522,7 +522,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
522
  public function array_first($array)
523
  {
524
  if (is_object($array)) $array = (array)$array;
525
- if (!is_array($array)) return $array;
526
  foreach ($array as $first) {
527
  return $first;
528
  }
@@ -535,22 +535,26 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
535
  * @param $discount_range
536
  * @return array|bool
537
  */
538
- public function getAdjustmentAmount($quantity, $discount_range)
539
  {
540
  $adjustment = array();
541
- if (!is_array($discount_range) && !is_object($discount_range)) return false;
542
 
543
- $range = $discount_range;
544
- $min = (isset($range->min_qty) ? $range->min_qty : 0);
545
- $max = (isset($range->max_qty) ? $range->max_qty : false);
 
546
 
547
- $type = (isset($range->discount_type) ? $range->discount_type : 'price_discount');
548
 
549
- if ($max == false) return false;
 
 
 
 
550
 
551
- if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
552
- $adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
553
  }
 
554
  return $adjustment;
555
  }
556
 
478
  case 'specific_products':
479
 
480
  if ($this->isItemInProductList($rule['type']['specific_products'], $item)) {
481
+ $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
482
  $applied_rules[$i]['name'] = $rule['name'];
483
  $applied_rules[$i]['item'] = $index;
484
  $applied_rules[$i]['id'] = $item['product_id'];
488
 
489
  case 'specific_category':
490
  if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
491
+ $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
492
  $applied_rules[$i]['name'] = $rule['name'];
493
  $applied_rules[$i]['item'] = $index;
494
  $applied_rules[$i]['id'] = $item['product_id'];
500
  case 'all_products':
501
  default:
502
 
503
+ $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
504
  $applied_rules[$i]['name'] = $rule['name'];
505
  $applied_rules[$i]['item'] = $index;
506
  $applied_rules[$i]['id'] = $item['product_id'];
522
  public function array_first($array)
523
  {
524
  if (is_object($array)) $array = (array)$array;
525
+ if (is_array($array)) return $array;
526
  foreach ($array as $first) {
527
  return $first;
528
  }
535
  * @param $discount_range
536
  * @return array|bool
537
  */
538
+ public function getAdjustmentAmount($quantity, $discount_ranges)
539
  {
540
  $adjustment = array();
541
+ foreach($discount_ranges as $discount_range) {
542
 
543
+ if (!is_array($discount_range) && !is_object($discount_range)) return false;
544
+ $range = is_array($discount_range) ? (object) $discount_range : $discount_range;
545
+ $min = (isset($range->min_qty) ? $range->min_qty : 0);
546
+ $max = (isset($range->max_qty) ? $range->max_qty : false);
547
 
548
+ $type = (isset($range->discount_type) ? $range->discount_type : 'price_discount');
549
 
550
+ if ($max == false) continue;
551
+
552
+ if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
553
+ $adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
554
+ }
555
 
 
 
556
  }
557
+
558
  return $adjustment;
559
  }
560
 
loader.php CHANGED
@@ -3,7 +3,7 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
  /**
4
  * Version of Woo Discount Rules.
5
  */
6
- define('WOO_DISCOUNT_VERSION', '1.4');
7
  /**
8
  * Required Version of WooCommerce to Run.
9
  */
3
  /**
4
  * Version of Woo Discount Rules.
5
  */
6
+ define('WOO_DISCOUNT_VERSION', '1.4.1');
7
  /**
8
  * Required Version of WooCommerce to Run.
9
  */
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.7
7
- Stable tag: 1.4
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -38,7 +38,26 @@ Encourage bulk purchases by providing discounts.
38
  * Shipping address based discount rule
39
 
40
  = Conditions based on =
41
- Products, categories, customers, customer roles, shipping location and more.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  = Rules apply based on =
44
 
@@ -89,5 +108,10 @@ More information could be found in the documentation
89
  5. Discounted price is applied in the Cart
90
 
91
  == Changelog ==
 
 
 
 
 
92
 
93
  == Upgrade notice ==
4
  Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.7
7
+ Stable tag: 1.4.1
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
38
  * Shipping address based discount rule
39
 
40
  = Conditions based on =
41
+ Conditions can be based products, categories, customers, customer roles, shipping location and more.
42
+
43
+ * All products
44
+ * Specific products / Selected products
45
+ * All categories (PRO feature)
46
+ * Selected categories (PRO feature)
47
+ * All customers (PRO feature)
48
+ * Selected customers (PRO feature)
49
+ * All customer roles (PRO feature)
50
+ * Selected customer roles (PRO feature)
51
+ * All Shipping locations (PRO feature)
52
+ * Selected shipping locations (PRO feature)
53
+
54
+ Examples:
55
+
56
+ * All Products get 10 % discount
57
+ * Shoes get 20 % discount, T-Shirts get 5% discount
58
+ * Adidas Special Edition Shoe (A specific product) gets 15 % discount for 10 days
59
+ * Members of Wholesale customers group gets 40 % discount, while Retail customers get 5 % discount
60
+ * Customers from California get 10 % discount while those from Texas get 5 %
61
 
62
  = Rules apply based on =
63
 
108
  5. Discounted price is applied in the Cart
109
 
110
  == Changelog ==
111
+ = 1.4.1 - 12/01/17 =
112
+ * Fix - saving price range in price rule condition
113
+
114
+ = 1.4.0 - 26/10/16 =
115
+ * PHP 5.3 compatibility added
116
 
117
  == Upgrade notice ==
view/template/discount-table.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
  if (!isset($table_data) || empty($table_data)) return false;
4
- $base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : []);
5
  ?>
6
  <table>
7
  <thead>
@@ -54,4 +54,4 @@ $base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data)
54
  }
55
  ?>
56
  </tbody>
57
- </table>
1
  <?php
2
  if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
  if (!isset($table_data) || empty($table_data)) return false;
4
+ $base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : array());
5
  ?>
6
  <table>
7
  <thead>
54
  }
55
  ?>
56
  </tbody>
57
+ </table>
view/view-pricing-rules.php CHANGED
@@ -239,27 +239,27 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
239
 
240
  // Make Dummy Element.
241
  if ($discount_range == '') $discount_range = array(0 => '');
242
-
243
  foreach ($discount_range as $index => $discount) {
244
  ?>
245
  <div class="discount_rule_list">
246
  <div class="form-group">
247
  <label>Min Quantity
248
  <input type="text"
249
- name="discount_range[<?php echo $index; ?>][min_qty]"
250
  class="form-control"
251
  value="<?php echo(isset($discount->min_qty) ? $discount->min_qty : ''); ?>"
252
  placeholder="ex. 1">
253
  </label>
254
  <label>Max Quantity
255
  <input type="text"
256
- name="discount_range[<?php echo $index; ?>][max_qty]"
257
  class="form-control"
258
  value="<?php echo(isset($discount->max_qty) ? $discount->max_qty : ''); ?>"
259
  placeholder="ex. 50"> </label>
260
  <label>Adjustment Type
261
  <select class="form-control"
262
- name="discount_range[<?php echo $index; ?>][discount_type]">
263
  <?php $opt = (isset($discount->discount_type) ? $discount->discount_type : ''); ?>
264
  <option
265
  value="percentage_discount" <?php if ($opt == 'percentage_discount') { ?> selected=selected <?php } ?> >
@@ -279,7 +279,7 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
279
  </select></label>
280
  <label>Value
281
  <input type="text"
282
- name="discount_range[<?php echo $index; ?>][to_discount]"
283
  class="form-control"
284
  value="<?php echo(isset($discount->to_discount) ? $discount->to_discount : ''); ?>"
285
  placeholder="ex. 50"> </label>
@@ -289,7 +289,7 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
289
 
290
  </div>
291
  </div>
292
- <?php } ?>
293
  <div align="right">
294
  <input type="button" class="button button-secondary restriction_tab" value="Previous">
295
  </div>
239
 
240
  // Make Dummy Element.
241
  if ($discount_range == '') $discount_range = array(0 => '');
242
+ $fieldIndex = 1;
243
  foreach ($discount_range as $index => $discount) {
244
  ?>
245
  <div class="discount_rule_list">
246
  <div class="form-group">
247
  <label>Min Quantity
248
  <input type="text"
249
+ name="discount_range[<?php echo $fieldIndex; ?>][min_qty]"
250
  class="form-control"
251
  value="<?php echo(isset($discount->min_qty) ? $discount->min_qty : ''); ?>"
252
  placeholder="ex. 1">
253
  </label>
254
  <label>Max Quantity
255
  <input type="text"
256
+ name="discount_range[<?php echo $fieldIndex; ?>][max_qty]"
257
  class="form-control"
258
  value="<?php echo(isset($discount->max_qty) ? $discount->max_qty : ''); ?>"
259
  placeholder="ex. 50"> </label>
260
  <label>Adjustment Type
261
  <select class="form-control"
262
+ name="discount_range[<?php echo $fieldIndex; ?>][discount_type]">
263
  <?php $opt = (isset($discount->discount_type) ? $discount->discount_type : ''); ?>
264
  <option
265
  value="percentage_discount" <?php if ($opt == 'percentage_discount') { ?> selected=selected <?php } ?> >
279
  </select></label>
280
  <label>Value
281
  <input type="text"
282
+ name="discount_range[<?php echo $fieldIndex; ?>][to_discount]"
283
  class="form-control"
284
  value="<?php echo(isset($discount->to_discount) ? $discount->to_discount : ''); ?>"
285
  placeholder="ex. 50"> </label>
289
 
290
  </div>
291
  </div>
292
+ <?php $fieldIndex++; } ?>
293
  <div align="right">
294
  <input type="button" class="button button-secondary restriction_tab" value="Previous">
295
  </div>
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.4
9
  * Requires at least: 4.6.1
10
  */
11
 
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.4.1
9
  * Requires at least: 4.6.1
10
  */
11