Discount Rules for WooCommerce - Version 1.5.9

Version Description

  • 18/04/18 =
  • Feature - Free shipping option in cart rule(Pro)
Download this release

Release Info

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

Code changes from version 1.5.8 to 1.5.9

assets/js/app.js CHANGED
@@ -1,4 +1,4 @@
1
- jQuery.noConflict();
2
  function validateFields(){
3
  var returnValue = false;
4
  (function ($) {
@@ -420,6 +420,16 @@ function validateFields(){
420
 
421
  });
422
 
 
 
 
 
 
 
 
 
 
 
423
  //on change discount type in price discount
424
  $(document).on('change', '.price_discount_type', function () {
425
  var discount_amount = $(this).closest('.discount_rule_list').find('.price_discount_amount');
@@ -640,6 +650,16 @@ function validateFields(){
640
  });
641
  });
642
 
 
 
 
 
 
 
 
 
 
 
643
  //--------------------------------------------------------------------------------------------------------------
644
  //-----------------------------------------------SIDE PANEL-----------------------------------------------------
645
  //--------------------------------------------------------------------------------------------------------------
1
+ //jQuery.noConflict();
2
  function validateFields(){
3
  var returnValue = false;
4
  (function ($) {
420
 
421
  });
422
 
423
+ $('#cart_rule_discount_type').on('change', function () {
424
+ var option = $(this).val();
425
+ if (option == 'shipping_price') {
426
+ $('#cart_rule_discount_value_con').hide();
427
+ } else {
428
+ $('#cart_rule_discount_value_con').show();
429
+ }
430
+ });
431
+ $('#cart_rule_discount_type').trigger('change');
432
+
433
  //on change discount type in price discount
434
  $(document).on('change', '.price_discount_type', function () {
435
  var discount_amount = $(this).closest('.discount_rule_list').find('.price_discount_amount');
650
  });
651
  });
652
 
653
+ $('select#enable_free_shipping').on('change', function () {
654
+ var option = $(this).val();
655
+ if (option == 'woodiscountfree') {
656
+ $('#woodiscount_settings_free_shipping_con').show();
657
+ } else {
658
+ $('#woodiscount_settings_free_shipping_con').hide();
659
+ }
660
+ });
661
+ $('select#enable_free_shipping').trigger('change');
662
+
663
  //--------------------------------------------------------------------------------------------------------------
664
  //-----------------------------------------------SIDE PANEL-----------------------------------------------------
665
  //--------------------------------------------------------------------------------------------------------------
includes/cart-rules.php CHANGED
@@ -71,6 +71,8 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
71
  public static $rules_loaded = 0;
72
  public static $cartRules;
73
 
 
 
74
  /**
75
  * FlycartWooDiscountRulesCartRules constructor.
76
  */
@@ -230,7 +232,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
230
  /**
231
  * To Analyzing the Pricing Rules to Apply the Discount in terms of price.
232
  */
233
- public function analyse($woocommerce)
234
  {
235
  global $woocommerce;
236
  // Re-arranging the Rules.
@@ -240,6 +242,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
240
  // Get Overall Discounts.
241
  $this->getDiscountAmount();
242
  // Add a Coupon Virtually (Temporary access).
 
243
  if ($this->discount_total != 0) {
244
  if(!FlycartWooDiscountRulesGeneralHelper::haveToApplyTheRules()) return false;
245
  add_filter('woocommerce_get_shop_coupon_data', array($this, 'addVirtualCoupon'), 10, 2);
@@ -539,7 +542,9 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
539
  if ($rule['enabled'] == true) {
540
  $discounts['name'][$index] = $rule['name'];
541
  $discounts['type'][$index] = $rule['discount_type'];
542
- if ($rule['discount_type'] == 'price_discount') {
 
 
543
  // Getting the Flat Rate of Discount.
544
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
545
  } else {
@@ -554,8 +559,10 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
554
  // Getting the Percentage level of Discount.
555
  $discounts['to_discount'][$index] = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
556
  }
557
- // Sum of Available discount list.
558
- $discount += $discounts['to_discount'][$index];
 
 
559
  // Update the status of the status of the discount rule.
560
  $discounts['is_enabled'][$index] = $rule['enabled'];
561
  break;
@@ -567,7 +574,9 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
567
  if ($rule['enabled'] == true) {
568
  $discounts['name'][$index] = $rule['name'];
569
  $discounts['type'][$index] = $rule['discount_type'];
570
- if ($rule['discount_type'] == 'price_discount') {
 
 
571
  // Getting the Flat Rate of Discount.
572
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
573
  } else {
@@ -582,8 +591,11 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
582
  // Getting the Percentage level of Discount.
583
  $discounts['to_discount'][$index] = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
584
  }
585
- // Sum of Available discount list.
586
- $discount += $discounts['to_discount'][$index];
 
 
 
587
  // Update the status of the status of the discount rule.
588
  $discounts['is_enabled'][$index] = $rule['enabled'];
589
  }
@@ -594,7 +606,10 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
594
  // Processing the Totals.
595
  foreach ($this->rule_sets as $index => $rule) {
596
  if ($rule['enabled'] == true) {
597
- if ($rule['discount_type'] == 'price_discount') {
 
 
 
598
  // Getting the Flat Rate of Discount.
599
  $newDiscount = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
600
  } else {
71
  public static $rules_loaded = 0;
72
  public static $cartRules;
73
 
74
+ public $has_free_shipping = 0;
75
+
76
  /**
77
  * FlycartWooDiscountRulesCartRules constructor.
78
  */
232
  /**
233
  * To Analyzing the Pricing Rules to Apply the Discount in terms of price.
234
  */
235
+ public function analyse($woocommerce, $free_shipping_check = 0)
236
  {
237
  global $woocommerce;
238
  // Re-arranging the Rules.
242
  // Get Overall Discounts.
243
  $this->getDiscountAmount();
244
  // Add a Coupon Virtually (Temporary access).
245
+ if(!$free_shipping_check)
246
  if ($this->discount_total != 0) {
247
  if(!FlycartWooDiscountRulesGeneralHelper::haveToApplyTheRules()) return false;
248
  add_filter('woocommerce_get_shop_coupon_data', array($this, 'addVirtualCoupon'), 10, 2);
542
  if ($rule['enabled'] == true) {
543
  $discounts['name'][$index] = $rule['name'];
544
  $discounts['type'][$index] = $rule['discount_type'];
545
+ if ($rule['discount_type'] == 'shipping_price') {
546
+ $this->has_free_shipping = 1;
547
+ } else if ($rule['discount_type'] == 'price_discount') {
548
  // Getting the Flat Rate of Discount.
549
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
550
  } else {
559
  // Getting the Percentage level of Discount.
560
  $discounts['to_discount'][$index] = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
561
  }
562
+ if(isset($discounts['to_discount']) && isset($discounts['to_discount'][$index])) {
563
+ // Sum of Available discount list.
564
+ $discount += $discounts['to_discount'][$index];
565
+ }
566
  // Update the status of the status of the discount rule.
567
  $discounts['is_enabled'][$index] = $rule['enabled'];
568
  break;
574
  if ($rule['enabled'] == true) {
575
  $discounts['name'][$index] = $rule['name'];
576
  $discounts['type'][$index] = $rule['discount_type'];
577
+ if ($rule['discount_type'] == 'shipping_price') {
578
+ $this->has_free_shipping = 1;
579
+ } else if ($rule['discount_type'] == 'price_discount') {
580
  // Getting the Flat Rate of Discount.
581
  $discounts['to_discount'][$index] = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
582
  } else {
591
  // Getting the Percentage level of Discount.
592
  $discounts['to_discount'][$index] = $this->calculateDiscount($subtotal, array('type' => 'percentage', 'value' => $rule['to_discount']));
593
  }
594
+ if(isset($discounts['to_discount']) && isset($discounts['to_discount'][$index])){
595
+ // Sum of Available discount list.
596
+ $discount += $discounts['to_discount'][$index];
597
+ }
598
+
599
  // Update the status of the status of the discount rule.
600
  $discounts['is_enabled'][$index] = $rule['enabled'];
601
  }
606
  // Processing the Totals.
607
  foreach ($this->rule_sets as $index => $rule) {
608
  if ($rule['enabled'] == true) {
609
+ if ($rule['discount_type'] == 'shipping_price') {
610
+ $this->has_free_shipping = 1;
611
+ $newDiscount = 0;
612
+ } else if ($rule['discount_type'] == 'price_discount') {
613
  // Getting the Flat Rate of Discount.
614
  $newDiscount = $this->calculateDiscount($this->sub_total, array('type' => 'price', 'value' => $rule['to_discount']));
615
  } else {
includes/discount-base.php CHANGED
@@ -24,6 +24,8 @@ if (!class_exists('FlycartWooDiscountBase')) {
24
  */
25
  private $instance = array();
26
 
 
 
27
  /**
28
  * FlycartWooDiscountBase constructor.
29
  */
@@ -67,11 +69,14 @@ if (!class_exists('FlycartWooDiscountBase')) {
67
  /**
68
  * Managing discount of Cart.
69
  */
70
- public function handleCartDiscount()
71
  {
72
  global $woocommerce;
73
  $cart_discount = $this->getInstance('FlycartWooDiscountRulesCartRules');
74
- $cart_discount->analyse($woocommerce);
 
 
 
75
  }
76
 
77
  /**
24
  */
25
  private $instance = array();
26
 
27
+ public $has_free_shipping = 0;
28
+
29
  /**
30
  * FlycartWooDiscountBase constructor.
31
  */
69
  /**
70
  * Managing discount of Cart.
71
  */
72
+ public function handleCartDiscount($free_shipping_check = 0)
73
  {
74
  global $woocommerce;
75
  $cart_discount = $this->getInstance('FlycartWooDiscountRulesCartRules');
76
+ $cart_discount->analyse($woocommerce, $free_shipping_check);
77
+ if($free_shipping_check){
78
+ $this->has_free_shipping = $cart_discount->has_free_shipping;
79
+ }
80
  }
81
 
82
  /**
loader.php CHANGED
@@ -205,5 +205,10 @@ if(!class_exists('FlycartWooDiscountRules')){
205
  * init Woo Discount Rules
206
  */
207
  if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
208
- FlycartWooDiscountRules::init();
 
 
 
 
 
209
  }
205
  * init Woo Discount Rules
206
  */
207
  if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
208
+ global $flycart_woo_discount_rules;
209
+ $flycart_woo_discount_rules = FlycartWooDiscountRules::init();
210
+ $purchase_helper = new FlycartWooDiscountRulesPurchase();
211
+ if($purchase_helper->isPro()){
212
+ include_once('includes/advanced/free_shipping_method.php');
213
+ }
214
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.8
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -243,6 +243,9 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
243
 
244
  == Changelog ==
245
 
 
 
 
246
  = 1.5.8 - 11/04/18 =
247
  * Feature - Option to add rule based on email domain in cart rules(Pro)
248
  * Improvement - Content improvement
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.9
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
243
 
244
  == Changelog ==
245
 
246
+ = 1.5.9 - 18/04/18 =
247
+ * Feature - Free shipping option in cart rule(Pro)
248
+
249
  = 1.5.8 - 11/04/18 =
250
  * Feature - Option to add rule based on email domain in cart rules(Pro)
251
  * Improvement - Content improvement
view/settings.php CHANGED
@@ -234,7 +234,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
234
  <div class="col-md-6">
235
  <select class="selectpicker" name="cart_setup">
236
  <option <?php if ($data['cart_setup'] == 'first') { ?> selected=selected <?php } ?>
237
- value="first" selected="selected"><?php esc_html_e('Apply first matched rule', 'woo-discount-rules'); ?>
238
  </option>
239
  <option
240
  value="all" <?php if (!$pro) { ?> disabled <?php }
@@ -269,6 +269,57 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
269
  <label><input type="radio" name="do_not_run_while_have_third_party_coupon" value="0" <?php echo ($data['do_not_run_while_have_third_party_coupon'] == 0)? 'checked': '' ?> /> <?php esc_html_e('No', 'woo-discount-rules'); ?></label>
270
  </div>
271
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  <div class="row form-group" style="display: none"><!-- Hide this because it is not required after v1.4.36 -->
273
  <div class="col-md-2">
274
  <label>
234
  <div class="col-md-6">
235
  <select class="selectpicker" name="cart_setup">
236
  <option <?php if ($data['cart_setup'] == 'first') { ?> selected=selected <?php } ?>
237
+ value="first"><?php esc_html_e('Apply first matched rule', 'woo-discount-rules'); ?>
238
  </option>
239
  <option
240
  value="all" <?php if (!$pro) { ?> disabled <?php }
269
  <label><input type="radio" name="do_not_run_while_have_third_party_coupon" value="0" <?php echo ($data['do_not_run_while_have_third_party_coupon'] == 0)? 'checked': '' ?> /> <?php esc_html_e('No', 'woo-discount-rules'); ?></label>
270
  </div>
271
  </div>
272
+ <div class="row form-group">
273
+ <div class="col-md-2">
274
+ <label>
275
+ <?php esc_html_e('Enable free shipping option', 'woo-discount-rules'); ?>
276
+ </label>
277
+ </div>
278
+ <?php $data['enable_free_shipping'] = (isset($data['enable_free_shipping']) ? $data['enable_free_shipping'] : "none"); ?>
279
+ <div class="col-md-6">
280
+ <?php
281
+ if(!$isPro){
282
+ esc_html_e('Supported in PRO version', 'woo-discount-rules');
283
+ ?>
284
+ <select name="enable_free_shipping" id="enable_free_shipping" style="display: none">
285
+ <option value="none"><?php esc_html_e('Disabled', 'woo-discount-rules'); ?></option>
286
+ </select>
287
+ <?php
288
+ } else {
289
+ ?>
290
+ <select class="selectpicker" name="enable_free_shipping" id="enable_free_shipping">
291
+ <option <?php if ($data['enable_free_shipping'] == "none") { ?> selected=selected <?php } ?>
292
+ value="none"><?php esc_html_e('Disabled', 'woo-discount-rules'); ?>
293
+ </option>
294
+ <option <?php if ($data['enable_free_shipping'] == "free_shipping") { ?> selected=selected <?php } ?>
295
+ value="free_shipping"><?php esc_html_e('Use Woocommerce free shipping', 'woo-discount-rules'); ?>
296
+ </option>
297
+ <option <?php if ($data['enable_free_shipping'] == "woodiscountfree") { ?> selected=selected <?php } ?>
298
+ value="woodiscountfree"><?php esc_html_e('Use Woo-Discount free shipping', 'woo-discount-rules'); ?>
299
+ </option>
300
+ </select>
301
+ <?php
302
+ }
303
+ ?>
304
+ </div>
305
+ </div>
306
+ <?php
307
+ if($isPro){
308
+ ?>
309
+ <div class="row form-group" id="woodiscount_settings_free_shipping_con">
310
+ <div class="col-md-2">
311
+ <label>
312
+ <?php esc_html_e('Free shipping text to be displayed', 'woo-discount-rules'); ?>
313
+ </label>
314
+ </div>
315
+ <div class="col-md-6">
316
+ <?php $data['free_shipping_text'] = ((isset($data['free_shipping_text']) && !empty($data['free_shipping_text'])) ? $data['free_shipping_text'] : __( 'Free Shipping', 'woo-discount-rules' )); ?>
317
+ <input type="text" class="" name="free_shipping_text"
318
+ value="<?php echo $data['free_shipping_text']; ?>"
319
+ placeholder="<?php esc_html_e('Free Shipping title', 'woo-discount-rules'); ?>">
320
+ </div>
321
+ </div>
322
+ <?php } ?>
323
  <div class="row form-group" style="display: none"><!-- Hide this because it is not required after v1.4.36 -->
324
  <div class="col-md-2">
325
  <label>
view/view-cart-rules.php CHANGED
@@ -497,7 +497,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
497
  <div class="col-md-2">
498
  <div class="form-group">
499
  <label> Discount Type :
500
- <select class="form-control" name="discount_type">
501
  <option
502
  value="percentage_discount" <?php if ($discount_type == 'percentage_discount') { ?> selected=selected <?php } ?>>
503
  Percentage Discount
@@ -512,11 +512,20 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
512
 
513
  <?php } ?>
514
  </option>
 
 
 
 
 
 
 
 
 
515
  </select>
516
  </label>
517
  </div>
518
  </div>
519
- <div class="col-md-2">
520
  <div class="form-group">
521
  <label> value :
522
  <input type="text" name="to_discount" class="form-control"
497
  <div class="col-md-2">
498
  <div class="form-group">
499
  <label> Discount Type :
500
+ <select class="form-control" id="cart_rule_discount_type" name="discount_type">
501
  <option
502
  value="percentage_discount" <?php if ($discount_type == 'percentage_discount') { ?> selected=selected <?php } ?>>
503
  Percentage Discount
512
 
513
  <?php } ?>
514
  </option>
515
+ <option
516
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="shipping_price" <?php }
517
+ if ($discount_type == 'shipping_price') { ?> selected=selected <?php } ?>>
518
+ <?php if (!$pro) { ?>
519
+ Free shipping <b><?php echo $suffix; ?></b>
520
+ <?php } else { ?>
521
+ Free shipping
522
+ <?php } ?>
523
+ </option>
524
  </select>
525
  </label>
526
  </div>
527
  </div>
528
+ <div class="col-md-2" id="cart_rule_discount_value_con" >
529
  <div class="form-group">
530
  <label> value :
531
  <input type="text" name="to_discount" class="form-control"
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.8
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.5.9
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1