Discount Rules for WooCommerce - Version 1.4.28

Version Description

  • 24/11/17 =
  • Fix - Buy any 3 from category (cumulative) and get 1 free
  • Feature - Buy any 3 from any selected product and get 1 cheapest product from selected list (pro)
Download this release

Release Info

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

Code changes from version 1.4.27 to 1.4.28

assets/js/app.js CHANGED
@@ -161,11 +161,14 @@ function validateFields(){
161
  '<label>Max Quantity <input type="text" name="discount_range[' + count + '][max_qty]" class="form-control" value="" placeholder="ex. 50"> </label> <label>Adjustment Type<select class="form-control price_discount_type" name="discount_range[' + count + '][discount_type]"> ' +
162
  '<option value="percentage_discount"> Percentage Discount </option> <option value="price_discount">Price Discount </option> <option value="product_discount">Product Discount </option> </select></label> <label>Value ' +
163
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
164
- form += '<div class="price_discount_product_list_con hide"><select class="product_list selectpicker price_discount_product_list" multiple name="discount_range[' + count + '][discount_product][]">';
165
- $("#product_list select.product_list option").each(function()
 
 
166
  {
167
  form += '<option value="'+$(this).val()+'">'+$(this).html()+'</option>';
168
- });
 
169
  form += '</select></div>';
170
  form += '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
171
  } else {
161
  '<label>Max Quantity <input type="text" name="discount_range[' + count + '][max_qty]" class="form-control" value="" placeholder="ex. 50"> </label> <label>Adjustment Type<select class="form-control price_discount_type" name="discount_range[' + count + '][discount_type]"> ' +
162
  '<option value="percentage_discount"> Percentage Discount </option> <option value="price_discount">Price Discount </option> <option value="product_discount">Product Discount </option> </select></label> <label>Value ' +
163
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
164
+ form += '<div class="price_discount_product_list_con hide">' +
165
+ ' Apply for <select class="" name="discount_range['+count+'][discount_product_option]"><option value="all">All selected</option><option value="any_cheapest">Any one cheapest </option>' +
166
+ '</select><select class="product_list selectpicker price_discount_product_list" multiple name="discount_range[' + count + '][discount_product][]">';
167
+ /* $("#product_list select.product_list option").each(function()
168
  {
169
  form += '<option value="'+$(this).val()+'">'+$(this).html()+'</option>';
170
+ });*/
171
+ form += $("#product_list select.product_list").first().html();
172
  form += '</select></div>';
173
  form += '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
174
  } else {
includes/pricing-rules-3.php CHANGED
@@ -436,7 +436,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
436
  $found = false;
437
  foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
438
  $_product = $values['data'];
439
- if ($_product->id == $productId){
440
  $_quantity = $values['quantity'];
441
  $_cart_item_key = $cart_item_key;
442
  $found = true;
@@ -473,7 +473,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
473
  $freeProductRule[0]['amount'] = array('price_discount' => $_product->get_price());
474
  $freeProductRule[0]['name'] = $free_product_detail['rule_name'];
475
  $freeProductRule[0]['item'] = $cart_item_key;
476
- $freeProductRule[0]['id'] = $_product->id;
477
  if(isset($quantity_exists[$productId]) && $quantity_exists[$productId] > 0){
478
  //discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
479
  $discount_price = $_product->get_price() - (($_product->get_price()/($quantity_exists[$productId]+$free_product_detail['count'])) * $quantity_exists[$productId]);
@@ -669,20 +669,43 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
669
  $applied_rules[$i]['name'] = $rule['name'];
670
  $applied_rules[$i]['item'] = $index;
671
  $applied_rules[$i]['id'] = $item['product_id'];
 
672
  }
673
 
674
  break;
675
 
676
  case 'specific_category':
677
  if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
 
678
  if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
679
  $totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
680
  $quantity = $totalQuantityInThisCategory;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
  }
682
- $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
683
- $applied_rules[$i]['name'] = $rule['name'];
684
- $applied_rules[$i]['item'] = $index;
685
- $applied_rules[$i]['id'] = $item['product_id'];
686
  }
687
 
688
 
@@ -698,6 +721,28 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
698
 
699
  break;
700
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
  }
702
  } else if(isset($rule['method']) && $rule['method'] == 'product_based'){
703
  $checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
@@ -716,7 +761,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
716
  $alreadyExists = 0;
717
  if(!empty($this->matched_sets[$cart_item_key])){
718
  foreach($this->matched_sets[$cart_item_key] as $machedRules){
719
- if($machedRules['rule_order'] == $id){
720
  $alreadyExists = 1;
721
  break;
722
  }
@@ -843,29 +888,70 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
843
 
844
  if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
845
  if($type == 'product_discount'){
846
- //to handle product discount
847
- $free_product = WC()->session->get('woo_discount_rules_get_free_product', array());
848
- $productIds = (isset($range->discount_product) ? $range->discount_product : array());
849
- if(!empty($productIds)){
850
- foreach ($productIds as $productId){
851
- if(isset($free_product[$productId])){
852
- $free_product[$productId]['count'] = $free_product[$productId]['count']+1;
853
- } else {
854
- $free_product[$productId]['count'] = 1;
855
- $free_product[$productId]['rule_name'] = $range->title;
 
 
 
 
 
 
 
 
856
  }
 
857
  }
858
- WC()->session->set('woo_discount_rules_get_free_product', $free_product);
859
  }
860
- $adjustment[$type] = (isset($range->discount_product) ? $range->discount_product : array());
861
  } else {
862
  $adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
863
  }
864
  }
 
 
 
865
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
866
  }
 
 
 
 
 
 
 
867
 
868
- return $adjustment;
 
 
 
869
  }
870
 
871
  /**
436
  $found = false;
437
  foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
438
  $_product = $values['data'];
439
+ if ($_product->get_id() == $productId){
440
  $_quantity = $values['quantity'];
441
  $_cart_item_key = $cart_item_key;
442
  $found = true;
473
  $freeProductRule[0]['amount'] = array('price_discount' => $_product->get_price());
474
  $freeProductRule[0]['name'] = $free_product_detail['rule_name'];
475
  $freeProductRule[0]['item'] = $cart_item_key;
476
+ $freeProductRule[0]['id'] = $_product->get_id();
477
  if(isset($quantity_exists[$productId]) && $quantity_exists[$productId] > 0){
478
  //discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
479
  $discount_price = $_product->get_price() - (($_product->get_price()/($quantity_exists[$productId]+$free_product_detail['count'])) * $quantity_exists[$productId]);
669
  $applied_rules[$i]['name'] = $rule['name'];
670
  $applied_rules[$i]['item'] = $index;
671
  $applied_rules[$i]['id'] = $item['product_id'];
672
+ $applied_rules[$i]['rule_order'] = $id;
673
  }
674
 
675
  break;
676
 
677
  case 'specific_category':
678
  if ($this->isItemInCategoryList($rule['type']['specific_category'], $item)) {
679
+ $alreadyExists = 0;
680
  if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
681
  $totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
682
  $quantity = $totalQuantityInThisCategory;
683
+ //Check for product_discount to apply the rule only once
684
+ if(isset($rule['discount'])){
685
+ if(!empty($rule['discount'])){
686
+ foreach($rule['discount'] as $discount_rules){
687
+ if(isset($discount_rules->discount_type) && $discount_rules->discount_type == 'product_discount'){
688
+ if(!empty($this->matched_sets)){
689
+ foreach($this->matched_sets as $machedRules){
690
+ foreach($machedRules as $machedRule){
691
+ if(isset($machedRule['rule_order']) && $machedRule['rule_order'] == $id){
692
+ $alreadyExists = 1;
693
+ }
694
+ }
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+ }
701
+ }
702
+ if(!$alreadyExists){
703
+ $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
704
+ $applied_rules[$i]['name'] = $rule['name'];
705
+ $applied_rules[$i]['item'] = $index;
706
+ $applied_rules[$i]['id'] = $item['product_id'];
707
+ $applied_rules[$i]['rule_order'] = $id;
708
  }
 
 
 
 
709
  }
710
 
711
 
721
 
722
  break;
723
  }
724
+ if(isset($applied_rules[$i]['amount']['product_ids'])){
725
+ if(!empty($applied_rules[$i]['amount']['product_ids'])){
726
+ $applyToProducts = $applied_rules[$i]['amount']['product_ids'];
727
+ $applyPercent = $applied_rules[$i]['amount'];
728
+ $applied_rules = array();
729
+ foreach ($applyToProducts as $key => $productId) {
730
+ foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
731
+ $_product = $values['data'];
732
+ if ($_product->get_id() == $productId){
733
+ $applied_rules_new = array();
734
+ $applied_rules_new['amount'] = $applyPercent;
735
+ $applied_rules_new['name'] = $rule['name'];
736
+ $applied_rules_new['item'] = $cart_item_key;
737
+ $applied_rules_new['id'] = $productId;
738
+ $applied_rules_new['rule_order'] = $id;
739
+ $applied_rules_new['apply_from'] = $item['product_id'];
740
+ $this->matched_sets[$cart_item_key][] = $applied_rules_new;
741
+ }
742
+ }
743
+ }
744
+ }
745
+ }
746
  }
747
  } else if(isset($rule['method']) && $rule['method'] == 'product_based'){
748
  $checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
761
  $alreadyExists = 0;
762
  if(!empty($this->matched_sets[$cart_item_key])){
763
  foreach($this->matched_sets[$cart_item_key] as $machedRules){
764
+ if(isset($machedRules['rule_order']) && $machedRules['rule_order'] == $id){
765
  $alreadyExists = 1;
766
  break;
767
  }
888
 
889
  if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
890
  if($type == 'product_discount'){
891
+ $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
892
+ $productIds = isset($range->discount_product) ? $range->discount_product : array();
893
+ if($discount_product_option == 'any_cheapest'){
894
+ $productCheapest = $this->getCheapestProductFromCart($productIds);
895
+ if(!empty($productCheapest)){
896
+ $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
897
+ }
898
+ } else {
899
+ //to handle product discount
900
+ $free_product = WC()->session->get('woo_discount_rules_get_free_product', array());
901
+ if(!empty($productIds)){
902
+ foreach ($productIds as $productId){
903
+ if(isset($free_product[$productId])){
904
+ $free_product[$productId]['count'] = $free_product[$productId]['count']+1;
905
+ } else {
906
+ $free_product[$productId]['count'] = 1;
907
+ $free_product[$productId]['rule_name'] = $range->title;
908
+ }
909
  }
910
+ WC()->session->set('woo_discount_rules_get_free_product', $free_product);
911
  }
912
+ $adjustment[$type] = $productIds;
913
  }
 
914
  } else {
915
  $adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
916
  }
917
  }
918
+ }
919
+ return $adjustment;
920
+ }
921
 
922
+ /**
923
+ * Get cheapest product
924
+ * */
925
+ public function getCheapestProductFromCart($products){
926
+ if(empty($products)) return array();
927
+ $cheapestProductValue = 0;
928
+ foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
929
+ $_product = $values['data'];
930
+ $productId = $this->getProductIdFromCartProduct($_product);
931
+ if(in_array($productId, $products)){
932
+ if($cheapestProductValue == 0){
933
+ $cheapestProductValue = $_product->get_price();
934
+ $cheapestProduct = $_product->get_id();
935
+ $quantity = $values['quantity'];
936
+ } else if($cheapestProductValue > $_product->get_price()){
937
+ $cheapestProductValue = $_product->get_price();
938
+ $cheapestProduct = $_product->get_id();
939
+ $quantity = $values['quantity'];
940
+ }
941
+ }
942
  }
943
+ if($cheapestProductValue > 0){
944
+ //discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
945
+ $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-1));
946
+ return array('product' => $cheapestProduct, 'percent' => $discount_price);
947
+ }
948
+ return array();
949
+ }
950
 
951
+ public function getProductIdFromCartProduct($product){
952
+ $id = $product->get_parent_id();
953
+ if(!$id) $id = $product->get_id();
954
+ return $id;
955
  }
956
 
957
  /**
includes/pricing-rules.php CHANGED
@@ -672,6 +672,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
672
  $applied_rules[$i]['name'] = $rule['name'];
673
  $applied_rules[$i]['item'] = $index;
674
  $applied_rules[$i]['id'] = $item['product_id'];
 
675
  }
676
 
677
  break;
@@ -681,11 +682,32 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
681
  if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
682
  $totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
683
  $quantity = $totalQuantityInThisCategory;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
  }
685
- $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
686
- $applied_rules[$i]['name'] = $rule['name'];
687
- $applied_rules[$i]['item'] = $index;
688
- $applied_rules[$i]['id'] = $item['product_id'];
689
  }
690
 
691
 
@@ -701,6 +723,28 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
701
 
702
  break;
703
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
704
  }
705
  } else if(isset($rule['method']) && $rule['method'] == 'product_based'){
706
  $checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
@@ -846,21 +890,29 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
846
 
847
  if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
848
  if($type == 'product_discount'){
849
- //to handle product discount
850
- $free_product = WC()->session->get('woo_discount_rules_get_free_product', array());
851
- $productIds = (isset($range->discount_product) ? $range->discount_product : array());
852
- if(!empty($productIds)){
853
- foreach ($productIds as $productId){
854
- if(isset($free_product[$productId])){
855
- $free_product[$productId]['count'] = $free_product[$productId]['count']+1;
856
- } else {
857
- $free_product[$productId]['count'] = 1;
858
- $free_product[$productId]['rule_name'] = $range->title;
 
 
 
 
 
 
 
 
859
  }
 
860
  }
861
- WC()->session->set('woo_discount_rules_get_free_product', $free_product);
862
  }
863
- $adjustment[$type] = (isset($range->discount_product) ? $range->discount_product : array());
864
  } else {
865
  $adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
866
  }
@@ -871,6 +923,41 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
871
  return $adjustment;
872
  }
873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
874
  /**
875
  * Validating the Active user with rule sets.
876
  *
672
  $applied_rules[$i]['name'] = $rule['name'];
673
  $applied_rules[$i]['item'] = $index;
674
  $applied_rules[$i]['id'] = $item['product_id'];
675
+ $applied_rules[$i]['rule_order'] = $id;
676
  }
677
 
678
  break;
682
  if(isset($rule['type']['is_cumulative']) && $rule['type']['is_cumulative']){
683
  $totalQuantityInThisCategory = $this->getProductQuantityInThisCategory($rule['type']['specific_category']);
684
  $quantity = $totalQuantityInThisCategory;
685
+ //Check for product_discount to apply the rule only once
686
+ if(isset($rule['discount'])){
687
+ if(!empty($rule['discount'])){
688
+ foreach($rule['discount'] as $discount_rules){
689
+ if(isset($discount_rules->discount_type) && $discount_rules->discount_type == 'product_discount'){
690
+ if(!empty($this->matched_sets)){
691
+ foreach($this->matched_sets as $machedRules){
692
+ foreach($machedRules as $machedRule){
693
+ if(isset($machedRule['rule_order']) && $machedRule['rule_order'] == $id){
694
+ $alreadyExists = 1;
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+ }
701
+ }
702
+ }
703
+ }
704
+ if(!$alreadyExists){
705
+ $applied_rules[$i]['amount'] = $this->getAdjustmentAmount($quantity, $this->array_first($rule['discount']));
706
+ $applied_rules[$i]['name'] = $rule['name'];
707
+ $applied_rules[$i]['item'] = $index;
708
+ $applied_rules[$i]['id'] = $item['product_id'];
709
+ $applied_rules[$i]['rule_order'] = $id;
710
  }
 
 
 
 
711
  }
712
 
713
 
723
 
724
  break;
725
  }
726
+ if(isset($applied_rules[$i]['amount']['product_ids'])){
727
+ if(!empty($applied_rules[$i]['amount']['product_ids'])){
728
+ $applyToProducts = $applied_rules[$i]['amount']['product_ids'];
729
+ $applyPercent = $applied_rules[$i]['amount'];
730
+ $applied_rules = array();
731
+ foreach ($applyToProducts as $key => $productId) {
732
+ foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
733
+ $_product = $values['data'];
734
+ if ($_product->id == $productId){
735
+ $applied_rules_new = array();
736
+ $applied_rules_new['amount'] = $applyPercent;
737
+ $applied_rules_new['name'] = $rule['name'];
738
+ $applied_rules_new['item'] = $cart_item_key;
739
+ $applied_rules_new['id'] = $productId;
740
+ $applied_rules_new['rule_order'] = $id;
741
+ $applied_rules_new['apply_from'] = $item['product_id'];
742
+ $this->matched_sets[$cart_item_key][] = $applied_rules_new;
743
+ }
744
+ }
745
+ }
746
+ }
747
+ }
748
  }
749
  } else if(isset($rule['method']) && $rule['method'] == 'product_based'){
750
  $checkRuleMatches = $this->checkProductBasedRuleMatches($rule, $item, $quantity);
890
 
891
  if ((int)$min <= (int)$quantity && (int)$max >= (int)$quantity) {
892
  if($type == 'product_discount'){
893
+ $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
894
+ $productIds = isset($range->discount_product) ? $range->discount_product : array();
895
+ if($discount_product_option == 'any_cheapest'){
896
+ $productCheapest = $this->getCheapestProductFromCart($productIds);
897
+ if(!empty($productCheapest)){
898
+ $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
899
+ }
900
+ } else {
901
+ //to handle product discount
902
+ $free_product = WC()->session->get('woo_discount_rules_get_free_product', array());
903
+ if(!empty($productIds)){
904
+ foreach ($productIds as $productId){
905
+ if(isset($free_product[$productId])){
906
+ $free_product[$productId]['count'] = $free_product[$productId]['count']+1;
907
+ } else {
908
+ $free_product[$productId]['count'] = 1;
909
+ $free_product[$productId]['rule_name'] = $range->title;
910
+ }
911
  }
912
+ WC()->session->set('woo_discount_rules_get_free_product', $free_product);
913
  }
914
+ $adjustment[$type] = $productIds;
915
  }
 
916
  } else {
917
  $adjustment[$type] = (isset($range->to_discount) ? $range->to_discount : 0);
918
  }
923
  return $adjustment;
924
  }
925
 
926
+ /**
927
+ * Get cheapest product
928
+ * */
929
+ public function getCheapestProductFromCart($products){
930
+ if(empty($products)) return array();
931
+ $cheapestProductValue = 0;
932
+ foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
933
+ $_product = $values['data'];
934
+ $productId = $this->getProductIdFromCartProduct($_product);
935
+ if(in_array($productId, $products)){
936
+ if($cheapestProductValue == 0){
937
+ $cheapestProductValue = $_product->price;
938
+ $cheapestProduct = $_product->id;
939
+ $quantity = $values['quantity'];
940
+ } else if($cheapestProductValue > $_product->price){
941
+ $cheapestProductValue = $_product->price;
942
+ $cheapestProduct = $_product->id;
943
+ $quantity = $values['quantity'];
944
+ }
945
+ }
946
+ }
947
+ if($cheapestProductValue > 0){
948
+ //discount_price = (original_price - ((original_price / (buy_qty + free_qty))*buy_qty))
949
+ $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-1));
950
+ return array('product' => $cheapestProduct, 'percent' => $discount_price);
951
+ }
952
+ return array();
953
+ }
954
+
955
+ public function getProductIdFromCartProduct($product){
956
+ $id = $product->parent_id;
957
+ if(!$id) $id = $product->id;
958
+ return $id;
959
+ }
960
+
961
  /**
962
  * Validating the Active user with rule sets.
963
  *
loader.php CHANGED
@@ -204,31 +204,31 @@ if (!function_exists('woo_discount_adminPageScript')) {
204
  }
205
 
206
  if ($status) {
207
- wp_register_style('woo_discount_style', WOO_DISCOUNT_URI . '/assets/css/style.css');
208
  wp_enqueue_style('woo_discount_style');
209
 
210
- wp_register_style('woo_discount_style_custom', WOO_DISCOUNT_URI . '/assets/css/custom.css');
211
  wp_enqueue_style('woo_discount_style_custom');
212
 
213
- wp_register_style('woo_discount_style_tab', WOO_DISCOUNT_URI . '/assets/css/tabbablePanel.css');
214
  wp_enqueue_style('woo_discount_style_tab');
215
 
216
  // For Implementing Select Picker Library.
217
- wp_register_style('woo_discount_style_select', WOO_DISCOUNT_URI . '/assets/css/bootstrap.select.min.css');
218
  wp_enqueue_style('woo_discount_style_select');
219
 
220
- wp_enqueue_script('woo_discount_script_select', WOO_DISCOUNT_URI . '/assets/js/bootstrap.select.min.js');
221
 
222
 
223
  // -------------------------------------------------------------------------------------------------------------
224
 
225
- wp_register_style('woo_discount_bootstrap', WOO_DISCOUNT_URI . '/assets/css/bootstrap.min.css');
226
  wp_enqueue_style('woo_discount_bootstrap');
227
 
228
- wp_register_script('woo_discount_jquery_ui_js_2', WOO_DISCOUNT_URI . '/assets/js/bootstrap.min.js');
229
  wp_enqueue_script('woo_discount_jquery_ui_js_2');
230
 
231
- wp_register_style('woo_discount_jquery_ui_css', WOO_DISCOUNT_URI . '/assets/css/jquery-ui.css');
232
  wp_enqueue_style('woo_discount_jquery_ui_css');
233
 
234
  wp_enqueue_script('jquery');
@@ -241,7 +241,7 @@ if (!function_exists('woo_discount_adminPageScript')) {
241
  // wp_register_script('woo_discount_select2_js', WOO_DISCOUNT_URI . '/assets/js/select2.min.js');
242
  // wp_enqueue_script('woo_discount_select2_js');
243
 
244
- wp_enqueue_script('woo_discount_script', WOO_DISCOUNT_URI . '/assets/js/app.js');
245
 
246
  }
247
  }
204
  }
205
 
206
  if ($status) {
207
+ wp_register_style('woo_discount_style', WOO_DISCOUNT_URI . '/assets/css/style.css', array(), WOO_DISCOUNT_VERSION);
208
  wp_enqueue_style('woo_discount_style');
209
 
210
+ wp_register_style('woo_discount_style_custom', WOO_DISCOUNT_URI . '/assets/css/custom.css', array(), WOO_DISCOUNT_VERSION);
211
  wp_enqueue_style('woo_discount_style_custom');
212
 
213
+ wp_register_style('woo_discount_style_tab', WOO_DISCOUNT_URI . '/assets/css/tabbablePanel.css', array(), WOO_DISCOUNT_VERSION);
214
  wp_enqueue_style('woo_discount_style_tab');
215
 
216
  // For Implementing Select Picker Library.
217
+ wp_register_style('woo_discount_style_select', WOO_DISCOUNT_URI . '/assets/css/bootstrap.select.min.css', array(), WOO_DISCOUNT_VERSION);
218
  wp_enqueue_style('woo_discount_style_select');
219
 
220
+ wp_enqueue_script('woo_discount_script_select', WOO_DISCOUNT_URI . '/assets/js/bootstrap.select.min.js', array(), WOO_DISCOUNT_VERSION);
221
 
222
 
223
  // -------------------------------------------------------------------------------------------------------------
224
 
225
+ wp_register_style('woo_discount_bootstrap', WOO_DISCOUNT_URI . '/assets/css/bootstrap.min.css', array(), WOO_DISCOUNT_VERSION);
226
  wp_enqueue_style('woo_discount_bootstrap');
227
 
228
+ wp_register_script('woo_discount_jquery_ui_js_2', WOO_DISCOUNT_URI . '/assets/js/bootstrap.min.js', array(), WOO_DISCOUNT_VERSION);
229
  wp_enqueue_script('woo_discount_jquery_ui_js_2');
230
 
231
+ wp_register_style('woo_discount_jquery_ui_css', WOO_DISCOUNT_URI . '/assets/css/jquery-ui.css', array(), WOO_DISCOUNT_VERSION);
232
  wp_enqueue_style('woo_discount_jquery_ui_css');
233
 
234
  wp_enqueue_script('jquery');
241
  // wp_register_script('woo_discount_select2_js', WOO_DISCOUNT_URI . '/assets/js/select2.min.js');
242
  // wp_enqueue_script('woo_discount_select2_js');
243
 
244
+ wp_enqueue_script('woo_discount_script', WOO_DISCOUNT_URI . '/assets/js/app.js', array(), WOO_DISCOUNT_VERSION);
245
 
246
  }
247
  }
readme.txt CHANGED
@@ -4,14 +4,14 @@ 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.9
7
- Stable tag: 1.4.27
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, promotions for your WooCommerce online store.
12
  == Description ==
13
 
14
- WooCommerce discount rules helps you to create any type of bulk discount and pricing rules in your WooCommerce store. Offer Product based, cart based discounts at a percentage or fixed amount. Increase your sales multifold by offering flexible, customised discounts and free products to your customers.
15
 
16
  Discount will be visible in Product Page, Product details page, Cart and in email invoices.
17
 
@@ -21,7 +21,8 @@ Discount will be visible in Product Page, Product details page, Cart and in emai
21
 
22
  * Percentage based Discount
23
  * Price based Discount
24
- * BOGO deals (Buy 1 get 1 free discounts)
 
25
 
26
  = Use cases =
27
 
@@ -44,6 +45,7 @@ Discount will be visible in Product Page, Product details page, Cart and in emai
44
  * Number of Items in cart
45
  * Total Sum of Item quantities
46
  * Shipping address based discount rule
 
47
 
48
  = Conditions based on =
49
  Conditions can be based products, categories, customers, customer roles, shipping location and more.
@@ -67,6 +69,7 @@ Examples:
67
  * Adidas Special Edition Shoe (A specific product) gets 15 % discount for 10 days
68
  * Members of Wholesale customers group gets 40 % discount, while Retail customers get 5 % discount
69
  * Customers from California get 10 % discount while those from Texas get 5 %
 
70
 
71
  = Rules apply based on =
72
 
@@ -172,10 +175,14 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
172
  2. Price rules and Cart rules
173
  3. Creating a price rule
174
  4. Example Promotion Offers created using Woo Discount rules
175
- 5. Discounted price is applied in the Cart
176
 
177
  == Changelog ==
178
 
 
 
 
 
179
  = 1.4.27 - 24/11/17 =
180
  * Fix – Category based rule not applying rule for variant product in cart
181
  * Feature – Search option in Select box for product and categories
@@ -240,4 +247,4 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
240
  = 1.4.0 - 26/10/16 =
241
  * PHP 5.3 compatibility added
242
 
243
- == 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.9
7
+ Stable tag: 1.4.28
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, promotions for your WooCommerce online store.
12
  == Description ==
13
 
14
+ WooCommerce discount rules helps you to create any type of bulk discount and pricing rules in your WooCommerce store. Offer Product quantity based discount, cart based discounts, discount for all products(Global level) at a percentage or fixed amount. Increase your sales multifold by offering flexible, customised discounts and free products to your customers.
15
 
16
  Discount will be visible in Product Page, Product details page, Cart and in email invoices.
17
 
21
 
22
  * Percentage based Discount
23
  * Price based Discount
24
+ * Product based discount
25
+ * Buy One Get One Discount(BOGO Deals)
26
 
27
  = Use cases =
28
 
45
  * Number of Items in cart
46
  * Total Sum of Item quantities
47
  * Shipping address based discount rule
48
+ * Discount based on First Product
49
 
50
  = Conditions based on =
51
  Conditions can be based products, categories, customers, customer roles, shipping location and more.
69
  * Adidas Special Edition Shoe (A specific product) gets 15 % discount for 10 days
70
  * Members of Wholesale customers group gets 40 % discount, while Retail customers get 5 % discount
71
  * Customers from California get 10 % discount while those from Texas get 5 %
72
+ * Buy a Mobile and get 20% off on headphone
73
 
74
  = Rules apply based on =
75
 
175
  2. Price rules and Cart rules
176
  3. Creating a price rule
177
  4. Example Promotion Offers created using Woo Discount rules
178
+ 5. Discounted price is applied in the Cart
179
 
180
  == Changelog ==
181
 
182
+ = 1.4.28 - 24/11/17 =
183
+ * Fix - Buy any 3 from category (cumulative) and get 1 free
184
+ * Feature - Buy any 3 from any selected product and get 1 cheapest product from selected list (pro)
185
+
186
  = 1.4.27 - 24/11/17 =
187
  * Fix – Category based rule not applying rule for variant product in cart
188
  * Feature – Search option in Select box for product and categories
247
  = 1.4.0 - 26/10/16 =
248
  * PHP 5.3 compatibility added
249
 
250
+ == Upgrade notice ==
view/view-pricing-rules.php CHANGED
@@ -393,8 +393,15 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
393
  value="<?php echo(isset($discount->to_discount) ? $discount->to_discount : ''); ?>"
394
  placeholder="ex. 50">
395
  <?php
396
- $products_list = (isset($discount->discount_product) ? $discount->discount_product : array()); ?>
 
 
397
  <div class="price_discount_product_list_con hide">
 
 
 
 
 
398
  <select class="product_list selectpicker price_discount_product_list" multiple
399
  name="discount_range[<?php echo $fieldIndex; ?>][discount_product][]">
400
  <?php foreach ($products as $index => $value) { ?>
393
  value="<?php echo(isset($discount->to_discount) ? $discount->to_discount : ''); ?>"
394
  placeholder="ex. 50">
395
  <?php
396
+ $products_list = (isset($discount->discount_product) ? $discount->discount_product : array());
397
+ $discount_product_option = (isset($discount->discount_product_option) ? $discount->discount_product_option : 'all');
398
+ ?>
399
  <div class="price_discount_product_list_con hide">
400
+ <?php esc_html_e('Apply for', 'woo-discount-rules') ?>
401
+ <select class="selectpicker" name="discount_range[<?php echo $fieldIndex; ?>][discount_product_option]">
402
+ <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
403
+ <option value="any_cheapest"<?php echo ($discount_product_option == 'any_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest', 'woo-discount-rules') ?></option>
404
+ </select>
405
  <select class="product_list selectpicker price_discount_product_list" multiple
406
  name="discount_range[<?php echo $fieldIndex; ?>][discount_product][]">
407
  <?php foreach ($products as $index => $value) { ?>
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.27
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.4.28
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1