Discount Rules for WooCommerce - Version 1.4.7

Version Description

Download this release

Release Info

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

Code changes from version 1.4.6 to 1.4.7

assets/js/app.js CHANGED
@@ -251,7 +251,8 @@ function validateFields(){
251
  '<optgroup label="Quantity Sum"><option value="quantity_least">Sum of item quantities at least</option><option value="quantity_less">Sum of item quantities less than</option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
252
  //'<optgroup label="Products In Cart"><option value="products_atleast_one">At least one product in cart</option><!-- These products should not present in the cart to apply. --><option value="products_not_in">None of selected products in cart</option></optgroup>' +
253
  //'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. --><option value="categories_atleast_one">At least one category in cart</option><!-- These Category should not present in the cart to apply. --><!--<option value="categories_not_in">None of selected categories in cart</option>--></optgroup>' +
254
- '<optgroup label="Customer Details (must be logged in)"><option value="users_in">User in list</option><option value="roles_in">User role in list</option><option value="shipping_countries_in">Shipping country in list</option></optgroup></select></label></div>' +
 
255
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
256
  '<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
257
  '<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
@@ -266,7 +267,8 @@ function validateFields(){
266
  '<optgroup label="Quantity Sum"><option disabled>Sum of item quantities at least <b>' + pro_suffix + '</b></option><option disabled>Sum of item quantities less than <b>' + pro_suffix + '</b></option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
267
  //'<optgroup label="Products In Cart"><option value="products_atleast_one">At least one product in cart</option><!-- These products should not present in the cart to apply. --><option value="products_not_in">None of selected products in cart</option></optgroup>' +
268
  //'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. --><option value="categories_atleast_one">At least one category in cart</option><!-- These Category should not present in the cart to apply. --><option value="categories_not_in">None of selected categories in cart</option></optgroup>' +
269
- '<optgroup label="Customer Details (must be logged in)"><option disabled>User in list <b>' + pro_suffix + '</b></option><option disabled>User role in list <b>' + pro_suffix + '</b></option><option disabled>Shipping country in list <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
 
270
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
271
  '<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
272
  '<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
251
  '<optgroup label="Quantity Sum"><option value="quantity_least">Sum of item quantities at least</option><option value="quantity_less">Sum of item quantities less than</option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
252
  //'<optgroup label="Products In Cart"><option value="products_atleast_one">At least one product in cart</option><!-- These products should not present in the cart to apply. --><option value="products_not_in">None of selected products in cart</option></optgroup>' +
253
  //'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. --><option value="categories_atleast_one">At least one category in cart</option><!-- These Category should not present in the cart to apply. --><!--<option value="categories_not_in">None of selected categories in cart</option>--></optgroup>' +
254
+ '<optgroup label="Customer Details (must be logged in)"><option value="users_in">User in list</option><option value="roles_in">User role in list</option><option value="shipping_countries_in">Shipping country in list</option></optgroup>' +
255
+ '<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup></select></label></div>' +
256
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
257
  '<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
258
  '<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
267
  '<optgroup label="Quantity Sum"><option disabled>Sum of item quantities at least <b>' + pro_suffix + '</b></option><option disabled>Sum of item quantities less than <b>' + pro_suffix + '</b></option></optgroup><!-- At least one of these should present in the cart to apply. -->' +
268
  //'<optgroup label="Products In Cart"><option value="products_atleast_one">At least one product in cart</option><!-- These products should not present in the cart to apply. --><option value="products_not_in">None of selected products in cart</option></optgroup>' +
269
  //'<optgroup label="Categories In Cart"><!-- At least one of these should present in the cart to apply. --><option value="categories_atleast_one">At least one category in cart</option><!-- These Category should not present in the cart to apply. --><option value="categories_not_in">None of selected categories in cart</option></optgroup>' +
270
+ '<optgroup label="Customer Details (must be logged in)"><option disabled>User in list <b>' + pro_suffix + '</b></option><option disabled>User role in list <b>' + pro_suffix + '</b></option><option disabled>Shipping country in list <b>' + pro_suffix + '</b></option></optgroup>' +
271
+ '<optgroup label="Customer Email Domain (Eg: edu)"><option disabled>Email ends with <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
272
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
273
  '<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
274
  '<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
includes/cart-rules.php CHANGED
@@ -717,6 +717,57 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
717
  }
718
  return true;
719
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
  /*case 'categories_atleast_one':
721
  if(count($rule)){
722
  $w_categories = $this->getCartProductCaregories();
@@ -735,6 +786,21 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
735
 
736
  }
737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
  /**
739
  * To get product categories
740
  * */
717
  }
718
  return true;
719
  break;
720
+ case 'customer_email_tld':
721
+ $rule = explode(',', $rule);
722
+ foreach($rule as $key => $r){
723
+ $rule[$key] = trim($r);
724
+ $rule[$key] = trim($rule[$key], '.');
725
+ }
726
+ $postData = $this->postData->get('post_data', '', 'raw');
727
+ $postDataArray = array();
728
+ if($postData != ''){
729
+ parse_str($postData, $postDataArray);
730
+ }
731
+ $postBillingEmail = $this->postData->get('billing_email', '', 'raw');
732
+ if($postBillingEmail != ''){
733
+ $postDataArray['billing_email'] = $postBillingEmail;
734
+ }
735
+ if(!get_current_user_id()){
736
+ $order_id = $this->postData->get('order-received', 0);
737
+ if($order_id){
738
+ $order = new WC_Order( $order_id);
739
+ $postDataArray['billing_email'] = $order->billing_email;
740
+ }
741
+ }
742
+ if(isset($postDataArray['billing_email']) && $postDataArray['billing_email'] != ''){
743
+ $user_email = $postDataArray['billing_email'];
744
+ if(get_current_user_id()){
745
+ update_user_meta(get_current_user_id(), 'billing_email', $user_email);
746
+ }
747
+ $tld = $this->getTLDFromEmail($user_email);
748
+ if(in_array($tld, $rule)){
749
+ return true;
750
+ }
751
+ } else if(get_current_user_id()){
752
+ $user_email = get_user_meta( get_current_user_id(), 'billing_email', true );
753
+ if($user_email != '' && !empty($user_email)){
754
+ $tld = $this->getTLDFromEmail($user_email);
755
+ if(in_array($tld, $rule)){
756
+ return true;
757
+ }
758
+ } else {
759
+ $user_details = get_userdata( get_current_user_id() );
760
+ if(isset($user_details->data->user_email) && $user_details->data->user_email != ''){
761
+ $user_email = $user_details->data->user_email;
762
+ $tld = $this->getTLDFromEmail($user_email);
763
+ if(in_array($tld, $rule)){
764
+ return true;
765
+ }
766
+ }
767
+ }
768
+ }
769
+ return false;
770
+ break;
771
  /*case 'categories_atleast_one':
772
  if(count($rule)){
773
  $w_categories = $this->getCartProductCaregories();
786
 
787
  }
788
 
789
+ /**
790
+ * Get tld from email
791
+ * */
792
+ protected function getTLDFromEmail($email){
793
+ $emailArray = explode('@', $email);
794
+ if(isset($emailArray[1])){
795
+ $emailDomainArray = explode('.', $emailArray[1]);
796
+ if(count($emailDomainArray)>1){
797
+ unset($emailDomainArray[0]);
798
+ }
799
+ return implode('.', $emailDomainArray);
800
+ }
801
+ return $emailArray[0];
802
+ }
803
+
804
  /**
805
  * To get product categories
806
  * */
includes/discount-base.php CHANGED
@@ -70,6 +70,20 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
70
  $cart_discount->analyse($woocommerce);
71
  }
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  /**
74
  * WooCommerce hook to change the name of a product.
75
  *
70
  $cart_discount->analyse($woocommerce);
71
  }
72
 
73
+ /**
74
+ * For adding script in checkout page
75
+ * */
76
+ public function addScriptInCheckoutPage(){
77
+ $script = '<script type="text/javascript">
78
+ jQuery( function( $ ) {
79
+ $( document.body ).on( "blur", "input#billing_email", function() {
80
+ $("select#billing_country").trigger("change");
81
+ })
82
+ });
83
+ </script>';
84
+ echo $script;
85
+ }
86
+
87
  /**
88
  * WooCommerce hook to change the name of a product.
89
  *
includes/pricing-rules.php CHANGED
@@ -872,7 +872,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
872
 
873
  $this->organizeRules();
874
 
875
- $discount_range = '';
876
  foreach ($this->rules as $index => $rule) {
877
  $status = false;
878
 
872
 
873
  $this->organizeRules();
874
 
875
+ $discount_range = array();
876
  foreach ($this->rules as $index => $rule) {
877
  $status = false;
878
 
loader.php CHANGED
@@ -97,6 +97,8 @@ add_action('wp_ajax_saveConfig', array($discountBase, 'saveConfig'));
97
  add_action('wp_ajax_UpdateStatus', array($discountBase, 'updateStatus'));
98
  add_action('wp_ajax_RemoveRule', array($discountBase, 'removeRule'));
99
 
 
 
100
  // ---------------------------------------------------------------------------------------------------------------------
101
 
102
  // --------------------------------------------------GENERAL FUNCTIONS--------------------------------------------------
97
  add_action('wp_ajax_UpdateStatus', array($discountBase, 'updateStatus'));
98
  add_action('wp_ajax_RemoveRule', array($discountBase, 'removeRule'));
99
 
100
+ add_action( 'woocommerce_after_checkout_form', array($discountBase, 'addScriptInCheckoutPage'));
101
+
102
  // ---------------------------------------------------------------------------------------------------------------------
103
 
104
  // --------------------------------------------------GENERAL FUNCTIONS--------------------------------------------------
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.6
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
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.7
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
view/view-cart-rules.php CHANGED
@@ -220,7 +220,7 @@ if (empty($discount_rules)) {
220
  <!-- --><?php //if (!$pro) { ?><!-- disabled --><?php //} else { ?><!-- value="categories_atleast_one" --><?php
221
  // } ?>
222
  <!-- --><?php //if ($type == 'categories_atleast_one') { ?><!-- selected="selected"-->
223
- <!-- --><?php //} ?><!-->-->
224
  <!-- At least one category in-->
225
  <!-- cart-->
226
  <!-- </option>-->
@@ -228,7 +228,7 @@ if (empty($discount_rules)) {
228
  <option
229
  value="categories_not_in"
230
  <?php //if ($type == 'categories_not_in') { ?><!-- selected=selected -->
231
- <?php //} ?><!-->
232
  <!-- None of selected categories in-->
233
  <!-- cart-->
234
  <!-- </option>-->
@@ -265,6 +265,18 @@ if (empty($discount_rules)) {
265
  <?php } ?>
266
  </option>
267
  </optgroup>
 
 
 
 
 
 
 
 
 
 
 
 
268
  </select>
269
  </label>
270
  </div>
220
  <!-- --><?php //if (!$pro) { ?><!-- disabled --><?php //} else { ?><!-- value="categories_atleast_one" --><?php
221
  // } ?>
222
  <!-- --><?php //if ($type == 'categories_atleast_one') { ?><!-- selected="selected"-->
223
+ <!-- --><?php //} ?><!-->
224
  <!-- At least one category in-->
225
  <!-- cart-->
226
  <!-- </option>-->
228
  <option
229
  value="categories_not_in"
230
  <?php //if ($type == 'categories_not_in') { ?><!-- selected=selected -->
231
+ <?php //} ?>
232
  <!-- None of selected categories in-->
233
  <!-- cart-->
234
  <!-- </option>-->
265
  <?php } ?>
266
  </option>
267
  </optgroup>
268
+ <optgroup label="Customer Email Domain (Eg: edu)">
269
+ <option
270
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="customer_email_tld" <?php
271
+ }
272
+ if ($type == 'customer_email_tld') { ?> selected=selected <?php } ?>>
273
+ <?php if (!$pro) { ?>
274
+ Email ends with <b><?php echo $suffix; ?></b>
275
+ <?php } else { ?>
276
+ Email ends with
277
+ <?php } ?>
278
+ </option>
279
+ </optgroup>
280
  </select>
281
  </label>
282
  </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.6
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.7
9
  * Requires at least: 4.6.1
10
  */
11