Discount Rules for WooCommerce - Version 1.4.36

Version Description

  • 04/01/18 =
  • Improvement - Load Product and users select box through ajax to avoid time out issue
Download this release

Release Info

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

Code changes from version 1.4.35 to 1.4.36

assets/js/app.js CHANGED
@@ -157,10 +157,13 @@ function validateFields(){
157
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
158
  form += '<div class="price_discount_product_list_con hide">' +
159
  ' 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>' +
160
- '</select><select class="product_list selectpicker price_discount_product_list" data-live-search="true" multiple name="discount_range[' + count + '][discount_product][]">';
161
-
162
- form += $("#product_list select.product_list").first().html();
163
- form += '</select></div>';
 
 
 
164
  form += '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
165
  } else {
166
  var form = '<div class="discount_rule_list"> <div class="form-group"><label>Min Quantity <input type="text" name="discount_range[' + count + '][min_qty]" class="form-control" value="" placeholder="ex. 1"></label>' +
@@ -174,6 +177,7 @@ function validateFields(){
174
  }
175
  $('#discount_rule_list').append(form);
176
  $('.product_list').selectpicker('refresh');
 
177
  });
178
 
179
  // Removing Discount Rule.
@@ -315,7 +319,13 @@ function validateFields(){
315
  '<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup>' +
316
  '<optgroup label="Purchase History"><option value="customer_based_on_purchase_history">Based on Purchase history</option></optgroup></select></label></div>' +
317
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
318
- '<div id="user_div_' + count + '"><select id="cart_user_list_' + count + '" class="user_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][users_to_apply][]"></select></div>' +
 
 
 
 
 
 
319
  '<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
320
  '<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
321
  '<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
@@ -348,8 +358,7 @@ function validateFields(){
348
  // Append to Cart rules list.
349
  $('#cart_rules_list').append(form);
350
 
351
- console.log('Count : ' + count);
352
- console.log(category_list);
353
 
354
  // Append the List of Values.
355
  $('#cart_user_list_' + count).append(user_list);
@@ -360,7 +369,6 @@ function validateFields(){
360
  $('#order_status_list_' + count).append(order_status_list);
361
 
362
  // Refresh the SelectPicker.
363
- $('.user_list').selectpicker('refresh');
364
  $('.product_list').selectpicker('refresh');
365
  $('.category_list').selectpicker('refresh');
366
  $('.roles_list').selectpicker('refresh');
157
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
158
  form += '<div class="price_discount_product_list_con hide">' +
159
  ' 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>' +
160
+ '</select>';
161
+ if($('#flycart_wdr_woocommerce_version').val() == 2){
162
+ form += '<input type="hidden" class="wc-product-search" style="width: 250px" data-multiple="true" name="discount_range[' + count + '][discount_product][]" data-placeholder="Search for a product&hellip;" data-action="woocommerce_json_search_products_and_variations" data-selected=""/>';
163
+ } else {
164
+ form += '<select class="wc-product-search" multiple="multiple" style="width: 250px" name="discount_range[' + count + '][discount_product][]" data-placeholder="Search for a product&hellip;" data-action="woocommerce_json_search_products_and_variations"></select>'
165
+ }
166
+ form += '</div>';
167
  form += '</label> <label>Action <a href=javascript:void(0) class="button button-secondary form-control remove_discount_range">Remove</a></label> </div> </div>';
168
  } else {
169
  var form = '<div class="discount_rule_list"> <div class="form-group"><label>Min Quantity <input type="text" name="discount_range[' + count + '][min_qty]" class="form-control" value="" placeholder="ex. 1"></label>' +
177
  }
178
  $('#discount_rule_list').append(form);
179
  $('.product_list').selectpicker('refresh');
180
+ $('.wc-product-search').trigger( 'wc-enhanced-select-init' );
181
  });
182
 
183
  // Removing Discount Rule.
319
  '<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup>' +
320
  '<optgroup label="Purchase History"><option value="customer_based_on_purchase_history">Based on Purchase history</option></optgroup></select></label></div>' +
321
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
322
+ '<div id="user_div_' + count + '">';
323
+ if($('#flycart_wdr_woocommerce_version').val() == 2){
324
+ form += '<input class="wc-customer-search" style="width: 250px" name="discount_rule[' + count + '][users_to_apply][]" data-placeholder="Search for a user&hellip;"/>';
325
+ } else {
326
+ form += '<select class="wc-customer-search" style="width: 250px" multiple="multiple" name="discount_rule[' + count + '][users_to_apply][]" data-placeholder="Search for a user&hellip;"></select>';
327
+ }
328
+ form += '</div>' +
329
  '<div id="product_div_' + count + '"><select id="cart_product_list_' + count + '" class="product_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
330
  '<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
331
  '<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" data-live-search="true" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
358
  // Append to Cart rules list.
359
  $('#cart_rules_list').append(form);
360
 
361
+ $('.wc-customer-search').trigger( 'wc-enhanced-select-init' );
 
362
 
363
  // Append the List of Values.
364
  $('#cart_user_list_' + count).append(user_list);
369
  $('#order_status_list_' + count).append(order_status_list);
370
 
371
  // Refresh the SelectPicker.
 
372
  $('.product_list').selectpicker('refresh');
373
  $('.category_list').selectpicker('refresh');
374
  $('.roles_list').selectpicker('refresh');
helper/general-helper.php CHANGED
@@ -32,9 +32,10 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
32
  ob_start();
33
  $config = $data;
34
  $pro = $this->isPro;
35
- $products = $this->getProductList();
36
  $category = $this->getCategoryList();
37
- $users = $this->getUserList();
 
38
  $userRoles = $this->getUserRoles();
39
  $userRoles['woo_discount_rules_guest'] = esc_html__('Guest', 'woo-discount-rules');
40
  $countries = $this->getAllCountries();
32
  ob_start();
33
  $config = $data;
34
  $pro = $this->isPro;
35
+ //$products = $this->getProductList();
36
  $category = $this->getCategoryList();
37
+ //$users = $this->getUserList();
38
+ FlycartWoocommerceVersion::wcVersion('3.0')? $flycart_wdr_woocommerce_version = 3: $flycart_wdr_woocommerce_version = 2;
39
  $userRoles = $this->getUserRoles();
40
  $userRoles['woo_discount_rules_guest'] = esc_html__('Guest', 'woo-discount-rules');
41
  $countries = $this->getAllCountries();
helper/woo-function.php CHANGED
@@ -17,6 +17,18 @@ if(!class_exists('FlycartWoocommerceVersion')){
17
  return false;
18
  }
19
  }
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
  }
22
 
@@ -43,7 +55,7 @@ if(!class_exists('FlycartWoocommerceProduct')){
43
  */
44
  public static function get_formatted_name($product)
45
  {
46
- if(FlycartWoocommerceVersion::wcVersion('3.0')){
47
  return $product->get_formatted_name();
48
  } else {
49
  $post_id = self::get_id($product);
@@ -110,7 +122,25 @@ if(!class_exists('FlycartWoocommerceProduct')){
110
  }
111
  }
112
  return $product->parent_id;
113
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
 
116
  /**
@@ -257,6 +287,95 @@ if(!class_exists('FlycartWoocommerceProduct')){
257
  }
258
  return $cat_id;
259
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  }
261
  }
262
 
@@ -301,8 +420,9 @@ if(!class_exists('FlycartWoocommerceCartProduct')){
301
  return WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data);
302
  } else {
303
  ob_start();
304
- return WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data);
305
  ob_end_flush();
 
306
  }
307
  }
308
  }
17
  return false;
18
  }
19
  }
20
+
21
+ /**
22
+ * backwardCompatibilityStringToArray
23
+ * @param $data
24
+ * @return array
25
+ * */
26
+ public static function backwardCompatibilityStringToArray($data)
27
+ {
28
+ if(!empty($data) && !is_array($data)) $data = explode(',', $data);
29
+
30
+ return $data;
31
+ }
32
  }
33
  }
34
 
55
  */
56
  public static function get_formatted_name($product)
57
  {
58
+ if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product , 'get_formatted_name')){
59
  return $product->get_formatted_name();
60
  } else {
61
  $post_id = self::get_id($product);
122
  }
123
  }
124
  return $product->parent_id;
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Get WooCommerce product children
130
+ *
131
+ * @access public
132
+ * @param array $product
133
+ * @return array
134
+ */
135
+ public static function get_children($product){
136
+ if(FlycartWoocommerceVersion::wcVersion('3.0') || method_exists($product, 'get_children')){
137
+ return $product->get_children();
138
+ } else {
139
+ if(isset($product->children)){
140
+ return $product->children;
141
+ }
142
+ return '';
143
+ }
144
  }
145
 
146
  /**
287
  }
288
  return $cat_id;
289
  }
290
+
291
+ /*
292
+ * Get WooCommerce get product select box
293
+ *
294
+ * @access public
295
+ * @param object $products_list
296
+ * @param string $name
297
+ * @return string
298
+ * */
299
+ public static function getProductAjaxSelectBox($products_list, $name){
300
+ $html = '';
301
+ if(FlycartWoocommerceVersion::wcVersion('3.0')){
302
+ $html .= '<select class="wc-product-search" style="width: 250px" multiple="multiple" name="'.$name.'[]" data-placeholder="'.esc_attr__( 'Search for a product&hellip;', 'woocommerce' ).'" data-action="woocommerce_json_search_products_and_variations">';
303
+ if(!empty($products_list) && count($products_list))
304
+ foreach ( $products_list as $product_id ) {
305
+ $product = self::wc_get_product($product_id);
306
+ if ( is_object( $product ) ) {
307
+ $html .= '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( self::get_formatted_name($product) ) . '</option>';
308
+ }
309
+ }
310
+ $html .= '</select>';
311
+ } else {
312
+ $html .= '<input type="hidden" class="wc-product-search" style="width: 250px" data-multiple="true" name="'.$name.'" data-placeholder="'.esc_attr__( 'Search for a product&hellip;', 'woocommerce' ).'" data-action="woocommerce_json_search_products_and_variations" data-selected="';
313
+ $json_ids = array();
314
+ if(!empty($products_list)){
315
+ if(!is_array($products_list)) $products_list = explode(',', $products_list);
316
+ if(!empty($products_list) && count($products_list)){
317
+ foreach ( $products_list as $product_id ) {
318
+ $product = self::wc_get_product( $product_id );
319
+ if ( is_object( $product ) ) {
320
+ $json_ids[ $product_id ] = wp_kses_post( self::get_formatted_name($product) );
321
+ }
322
+ }
323
+ $html .= esc_attr( json_encode( $json_ids ) );
324
+ }
325
+ }
326
+
327
+
328
+ $html .= '" value="'.implode( ',', array_keys( $json_ids ) ).'" /> ';
329
+ }
330
+
331
+ return $html;
332
+ }
333
+
334
+ /*
335
+ * Get WooCommerce get product select box
336
+ *
337
+ * @access public
338
+ * @param object $users_list
339
+ * @param string $name
340
+ * @return string
341
+ * */
342
+ public static function getUserAjaxSelectBox($users_list, $name){
343
+ $html = '';
344
+ if(FlycartWoocommerceVersion::wcVersion('3.0')){
345
+ $html .= '<select class="wc-customer-search" style="width: 250px" multiple="multiple" name="'.$name.'[]" data-placeholder="'.esc_attr__( 'Search for a user&hellip;', 'woocommerce' ).'" data-allow_clear="true">';
346
+
347
+ if(!empty($users_list) && count($users_list))
348
+ foreach ( $users_list as $user_id ) {
349
+ $user = get_userdata($user_id);
350
+ if ( is_object( $user ) ) {
351
+ $formattedName = $user->user_firstname.' '.$user->user_lastname.' (#'.$user->ID.' - '. $user->user_email.')';
352
+ $html .= '<option value="' . esc_attr( $user_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post($formattedName) . '</option>';
353
+ }
354
+ }
355
+ $html .= '</select>';
356
+ } else {
357
+ $html .= '<input type="hidden" class="wc-customer-search" style="width: 250px" data-multiple="true" name="'.$name.'" data-placeholder="'.esc_attr__( 'Search for a user&hellip;', 'woocommerce' ).'" data-allow_clear="true" data-selected="';
358
+ $json_ids = array();
359
+ if(!empty($users_list)){
360
+ if(!is_array($users_list)) $users_list = explode(',', $users_list);
361
+ if(!empty($users_list) && count($users_list)){
362
+ foreach ( $users_list as $user_id ) {
363
+ $user = get_userdata($user_id);
364
+ if ( is_object( $user ) ) {
365
+ $formattedName = $user->user_firstname.' '.$user->user_lastname.' (#'.$user->ID.' - '. $user->user_email.')';
366
+ $json_ids[ $user_id ] = wp_kses_post( $formattedName );
367
+ }
368
+ }
369
+ $html .= esc_attr( json_encode( $json_ids ) );
370
+ }
371
+ }
372
+
373
+
374
+ $html .= '" value="'.implode( ',', array_keys( $json_ids ) ).'" /> ';
375
+ }
376
+
377
+ return $html;
378
+ }
379
  }
380
  }
381
 
420
  return WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data);
421
  } else {
422
  ob_start();
423
+ $addToCart = WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data);
424
  ob_end_flush();
425
+ return $addToCart;
426
  }
427
  }
428
  }
includes/cart-rules.php CHANGED
@@ -719,6 +719,7 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
719
 
720
  // Logged In Users.
721
  case 'users_in':
 
722
  if (get_current_user_id() == 0 || !in_array(get_current_user_id(), $rule)) {
723
  return false;
724
  }
719
 
720
  // Logged In Users.
721
  case 'users_in':
722
+ $rule = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($rule);
723
  if (get_current_user_id() == 0 || !in_array(get_current_user_id(), $rule)) {
724
  return false;
725
  }
includes/discount-base.php CHANGED
@@ -630,6 +630,9 @@ if (!class_exists('FlycartWooDiscountBase')) {
630
 
631
  wp_enqueue_script('woo_discount_script', WOO_DISCOUNT_URI . '/assets/js/app.js', array(), WOO_DISCOUNT_VERSION);
632
 
 
 
 
633
  }
634
  }
635
 
630
 
631
  wp_enqueue_script('woo_discount_script', WOO_DISCOUNT_URI . '/assets/js/app.js', array(), WOO_DISCOUNT_VERSION);
632
 
633
+ //To load woocommerce product select
634
+ wp_enqueue_script( 'wc-enhanced-select' );
635
+ wp_enqueue_style( 'woocommerce_admin_styles' );
636
  }
637
  }
638
 
includes/pricing-rules.php CHANGED
@@ -850,7 +850,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
850
  $quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
851
  $quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
852
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
 
853
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
 
854
 
855
  $product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
856
  $discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
@@ -952,6 +954,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
952
  if($type == 'product_discount'){
953
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
954
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
 
955
  if($discount_product_option == 'any_cheapest'){
956
  $productCheapest = $this->getCheapestProductFromCart($productIds);
957
  if(!empty($productCheapest)){
@@ -1024,7 +1027,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1024
 
1025
  $users = $rule->users_to_apply;
1026
 
1027
- if (is_string($users)) $users = json_decode($users, True);
 
 
1028
 
1029
  if (!is_array($users)) return $allowed;
1030
 
@@ -1158,6 +1163,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1158
  $specific_product_list = array();
1159
  if (is_string($rule->product_to_apply)) {
1160
  $specific_product_list = json_decode($rule->product_to_apply, true);
 
1161
  }
1162
  return $specific_product_list;
1163
  }
@@ -1280,6 +1286,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1280
  $status = true;
1281
  } else {
1282
  $users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
 
1283
  if(empty($users)) $users = array();
1284
  $user_id = get_current_user_id();
1285
  if (count(array_intersect($users, array($user_id))) > 0) {
@@ -1292,6 +1299,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1292
 
1293
  // Check with Product Filter.
1294
  $products_to_apply = json_decode($rule->product_to_apply);
 
1295
 
1296
  if ($rule->product_to_apply == null) $status = true;
1297
 
@@ -1342,7 +1350,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1342
  } else if(isset($rule->rule_method) && $rule->rule_method == 'product_based'){
1343
  $product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
1344
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
 
1345
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
 
1346
  if (in_array($id, $product_to_buy) || in_array($id, $product_to_apply)) {
1347
  $product_based_discounts = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
1348
  $product_based_discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
@@ -1371,7 +1381,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1371
  $product_quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
1372
  $product_quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
1373
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
 
1374
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
 
1375
  $condition = esc_html__('Buy', 'woo-discount-rules');
1376
 
1377
  switch ($product_quantity_rule) {
@@ -1472,6 +1484,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1472
  $discount_type = isset($value->discount_type) ? $value->discount_type : 0;
1473
  $to_discount = isset($value->to_discount) ? $value->to_discount : 0;
1474
  $product_discount = isset($value->discount_product) ? $value->discount_product : array();
 
1475
  if (isset($base_config['show_discount_title_table'])) {
1476
  }
1477
  $condition = $min .' - ' . $max;
@@ -1723,9 +1736,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1723
  * */
1724
  public function replaceVisiblePricesForVariant($data, $product, $variations)
1725
  {
1726
- if(FlycartWoocommerceVersion::wcVersion('3.0')){
1727
- return $data;
1728
- }
1729
  $item_price = $data['price_html'];
1730
  $config = new FlycartWooDiscountBase();
1731
  $config = $config->getBaseConfig();
@@ -1835,6 +1847,16 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1835
  $price = FlycartWoocommerceProduct::get_price($cart_item);
1836
  }
1837
 
 
 
 
 
 
 
 
 
 
 
1838
  $amount = 0;
1839
  $discount = 0;
1840
  if ($type == 'first') {
850
  $quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
851
  $quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
852
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
853
+ $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
854
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
855
+ $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
856
 
857
  $product_based_discounts = isset($rule['product_based_discount']) ? $rule['product_based_discount'] : array();
858
  $discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
954
  if($type == 'product_discount'){
955
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
956
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
957
+ $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
958
  if($discount_product_option == 'any_cheapest'){
959
  $productCheapest = $this->getCheapestProductFromCart($productIds);
960
  if(!empty($productCheapest)){
1027
 
1028
  $users = $rule->users_to_apply;
1029
 
1030
+ if (is_string($users)) $users = json_decode($users, true);
1031
+
1032
+ $users = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($users);
1033
 
1034
  if (!is_array($users)) return $allowed;
1035
 
1163
  $specific_product_list = array();
1164
  if (is_string($rule->product_to_apply)) {
1165
  $specific_product_list = json_decode($rule->product_to_apply, true);
1166
+ $specific_product_list = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($specific_product_list);
1167
  }
1168
  return $specific_product_list;
1169
  }
1286
  $status = true;
1287
  } else {
1288
  $users = (is_string($rule->users_to_apply) ? json_decode($rule->users_to_apply, true) : array());
1289
+ $users = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($users);
1290
  if(empty($users)) $users = array();
1291
  $user_id = get_current_user_id();
1292
  if (count(array_intersect($users, array($user_id))) > 0) {
1299
 
1300
  // Check with Product Filter.
1301
  $products_to_apply = json_decode($rule->product_to_apply);
1302
+ $products_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($products_to_apply);
1303
 
1304
  if ($rule->product_to_apply == null) $status = true;
1305
 
1350
  } else if(isset($rule->rule_method) && $rule->rule_method == 'product_based'){
1351
  $product_based_conditions = json_decode((isset($rule->product_based_condition) ? $rule->product_based_condition : '{}'), true);
1352
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
1353
+ $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
1354
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
1355
+ $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
1356
  if (in_array($id, $product_to_buy) || in_array($id, $product_to_apply)) {
1357
  $product_based_discounts = json_decode((isset($rule->product_based_discount) ? $rule->product_based_discount : '{}'), true);
1358
  $product_based_discount_type = isset($product_based_discounts['discount_type']) ? $product_based_discounts['discount_type'] : 'percentage_discount';
1381
  $product_quantity_from = isset($product_based_conditions['product_quantity_from']) ? $product_based_conditions['product_quantity_from'] : '';
1382
  $product_quantity_to = isset($product_based_conditions['product_quantity_to']) ? $product_based_conditions['product_quantity_to'] : '';
1383
  $product_to_buy = isset($product_based_conditions['product_to_buy']) ? $product_based_conditions['product_to_buy'] : array();
1384
+ $product_to_buy = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_buy);
1385
  $product_to_apply = isset($product_based_conditions['product_to_apply']) ? $product_based_conditions['product_to_apply'] : array();
1386
+ $product_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_to_apply);
1387
  $condition = esc_html__('Buy', 'woo-discount-rules');
1388
 
1389
  switch ($product_quantity_rule) {
1484
  $discount_type = isset($value->discount_type) ? $value->discount_type : 0;
1485
  $to_discount = isset($value->to_discount) ? $value->to_discount : 0;
1486
  $product_discount = isset($value->discount_product) ? $value->discount_product : array();
1487
+ $product_discount = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($product_discount);
1488
  if (isset($base_config['show_discount_title_table'])) {
1489
  }
1490
  $condition = $min .' - ' . $max;
1736
  * */
1737
  public function replaceVisiblePricesForVariant($data, $product, $variations)
1738
  {
1739
+ if(FlycartWoocommerceVersion::wcVersion('3.0')) return $data;
1740
+
 
1741
  $item_price = $data['price_html'];
1742
  $config = new FlycartWooDiscountBase();
1743
  $config = $config->getBaseConfig();
1847
  $price = FlycartWoocommerceProduct::get_price($cart_item);
1848
  }
1849
 
1850
+ if(!($price > 0)){
1851
+ $children = FlycartWoocommerceProduct::get_children($cart_item);
1852
+ if(!empty($children) && is_array($children)){
1853
+ if(isset($children[0])){
1854
+ $product = FlycartWoocommerceProduct::wc_get_product($children[0]);
1855
+ $price = FlycartWoocommerceProduct::get_price($product);
1856
+ }
1857
+ }
1858
+ }
1859
+
1860
  $amount = 0;
1861
  $discount = 0;
1862
  if ($type == 'first') {
readme.txt CHANGED
@@ -1,38 +1,38 @@
1
  === WooCommerce Discount Rules ===
2
  Contributors: flycart
3
  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.35
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 discounts, dynamic pricing and advanced discount rules in your WooCommerce store. 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, user roles, Cart items and much more.
15
 
16
- Now you can set Bulk Discounts for each Product Variation, Bulk Discounts for different user roles.
17
 
18
- Discounts will be visible in product Page, product details page, cart and in email invoices.
19
 
20
  Display the pricing discount table beautifully on the product page. Start selling more and retain customers by running promotions with the best dynamic pricing and discount plugin for WooCommerce.
21
 
22
- [View Demo](http://demo.flycart.org/woo-discount-rules) | [Documentation with real examples](https://www.flycart.org/docs/wordpress/woo-discount-rules) | [Ask Questions](https://www.flycart.org/support) | [PRO version](https://www.flycart.org/products/wordpress/woocommerce-discount-rules) | [Examples](https://www.flycart.org/woocommerce-discount-rules-examples)
23
 
24
  = DISCOUNT TYPES AND FEATURES =
25
 
26
  * Percentage based discounts in WooCommerce
27
  * Price based discounts
28
  * Product based discounts
29
- * Dynamic pricing and discounts in WooCommerce
30
- * Option to set discounts for each variant
31
- * Buy One and Get One Free discounts in WooCommerce (BOGO Deals)
32
  * Cart discounts in WooCommerce
33
- * User role based dynamic pricing and discounts for your WooCommerce store
34
- * Dependant product based discounts (Buy Product A and get discount on Product B)
35
- * Option to set discount for each product variant.
36
  * Option to set Discount for All Products or Global Discount
37
  * Display or hide the Discount table in Product Page
38
  * Option to show or hide the discounted price
@@ -155,7 +155,7 @@ Conditions can be based products, categories, customers, customer roles, shippin
155
 
156
  = Documentation =
157
 
158
- [https://www.flycart.org/docs/wordpress/woo-discount-rules](https://www.flycart.org/docs/wordpress/woo-discount-rules)
159
 
160
  == Installation ==
161
  Just use the WordPress installer or upload to the /wp-content/plugins folder. Then Activate the WooCommerce Email Builder and Customizer plugin.
@@ -238,6 +238,9 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
238
 
239
  == Changelog ==
240
 
 
 
 
241
  = 1.4.35 - 28/12/17 =
242
  * Fix - Rule not applied for specific product in cart
243
 
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.4.36
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 discounts, dynamic pricing and advanced discounts in your WooCommerce store. 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, user roles, Cart items and much more.
15
 
16
+ You can set discounts for product and also for each product variation. That is you can apply discount rules for variants as well.
17
 
18
+ Discounts will be visible in product page, product details page, cart, checkout and in email notifications.
19
 
20
  Display the pricing discount table beautifully on the product page. Start selling more and retain customers by running promotions with the best dynamic pricing and discount plugin for WooCommerce.
21
 
22
+ [View Demo](http://demo.flycart.org/woo-discount-rules) | [Documentation with real examples](http://docs.flycart.org/woocommerce-discount-rules) | [Ask Questions](https://www.flycart.org/support) | [PRO version](https://www.flycart.org/products/wordpress/woocommerce-discount-rules) | [Examples](https://www.flycart.org/woocommerce-discount-rules-examples)
23
 
24
  = DISCOUNT TYPES AND FEATURES =
25
 
26
  * Percentage based discounts in WooCommerce
27
  * Price based discounts
28
  * Product based discounts
29
+ * Dynamic pricing and discounts for WooCommerce
30
+ * Option to set discounts for each variant - PRO feature
31
+ * Buy One and Get One Free discounts in WooCommerce (BOGO Deals) - PRO feature
32
  * Cart discounts in WooCommerce
33
+ * User role based dynamic pricing and discounts for your WooCommerce store - PRO feature
34
+ * Dependant product based discounts (Buy Product A and get discount on Product B) - PRO feature
35
+ * Option to set discount for each product variant. - PRO feature
36
  * Option to set Discount for All Products or Global Discount
37
  * Display or hide the Discount table in Product Page
38
  * Option to show or hide the discounted price
155
 
156
  = Documentation =
157
 
158
+ [http://docs.flycart.org/woocommerce-discount-rules](http://docs.flycart.org/woocommerce-discount-rules)
159
 
160
  == Installation ==
161
  Just use the WordPress installer or upload to the /wp-content/plugins folder. Then Activate the WooCommerce Email Builder and Customizer plugin.
238
 
239
  == Changelog ==
240
 
241
+ = 1.4.36 - 04/01/18 =
242
+ * Improvement - Load Product and users select box through ajax to avoid time out issue
243
+
244
  = 1.4.35 - 28/12/17 =
245
  * Fix - Rule not applied for specific product in cart
246
 
view/view-cart-rules.php CHANGED
@@ -285,14 +285,9 @@ if (empty($discount_rules)) {
285
  //
286
  ?>
287
  <div id="user_div_<?php echo $i; ?>" <?php echo $class; ?>>
288
- <select class="user_list selectpicker"
289
- id="cart_user_list_<?php echo $i; ?>" multiple
290
- name="discount_rule[<?php echo $i; ?>][users_to_apply][]">
291
- <?php foreach ($users as $index => $user) { ?>
292
- <option
293
- value="<?php echo $index; ?>"<?php if (in_array($index, $users_list)) { ?> selected=selected <?php } ?>><?php echo $user; ?></option>
294
- <?php } ?>
295
- </select>
296
  </div>
297
  <?php
298
  $products_list = array();
@@ -501,6 +496,7 @@ if (empty($discount_rules)) {
501
  <input type="hidden" id="admin_path" value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
502
  <input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
503
  <input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
 
504
  </form>
505
  </div>
506
 
285
  //
286
  ?>
287
  <div id="user_div_<?php echo $i; ?>" <?php echo $class; ?>>
288
+ <?php
289
+ echo FlycartWoocommerceProduct::getUserAjaxSelectBox($users_list, "discount_rule[".$i."][users_to_apply]");
290
+ ?>
 
 
 
 
 
291
  </div>
292
  <?php
293
  $products_list = array();
496
  <input type="hidden" id="admin_path" value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
497
  <input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
498
  <input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
499
+ <input type="hidden" id="flycart_wdr_woocommerce_version" value="<?php echo $flycart_wdr_woocommerce_version; ?>">
500
  </form>
501
  </div>
502
 
view/view-pricing-rules.php CHANGED
@@ -153,14 +153,9 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
153
  </option>
154
  </select>
155
  <div class="form-group" id="product_list">
156
- <?php $products_list = json_decode((isset($data->product_to_apply) ? $data->product_to_apply : '{}'), true); ?>
157
- <select class="product_list selectpicker" multiple
158
- name="product_to_apply[]">
159
- <?php foreach ($products as $index => $value) { ?>
160
- <option
161
- value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
162
- <?php } ?>
163
- </select>
164
  </div>
165
  <div class="form-group" id="category_list">
166
  <?php $category_list = json_decode((isset($data->category_to_apply) ? $data->category_to_apply : '{}'), true); ?>
@@ -203,13 +198,9 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
203
  </option>
204
  </select>
205
  <div class="form-group" id="user_list">
206
- <?php $users_list = json_decode((isset($data->users_to_apply) ? $data->users_to_apply : '{}'), true); ?>
207
- <select class="user_list selectpicker" multiple name="users_to_apply[]">
208
- <?php foreach ($users as $index => $value) { ?>
209
- <option
210
- value="<?php echo $index; ?>"<?php if (in_array($index, $users_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
211
- <?php } ?>
212
- </select>
213
  </div>
214
  </div>
215
  </div>
@@ -314,19 +305,9 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
314
  <input placeholder="<?php esc_html_e('Quantity', 'woo-discount-rules') ?>" type="text" name="product_based_condition[product_quantity_to]" value="<?php echo $product_based_condition_product_quantity_to; ?>"/ >
315
  </div>
316
  <label ><?php esc_html_e('Product(s) from', 'woo-discount-rules')?></label>
317
- <select class="product_list selectpicker" multiple name="product_based_condition[product_to_buy][]">
318
- <?php foreach ($products as $index => $value) { ?>
319
- <option
320
- value="<?php echo $index; ?>" <?php if (in_array($index, $product_based_condition_product_to_buy)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
321
- <?php } ?>
322
- </select>
323
  <label ><?php esc_html_e('and get discount in ', 'woo-discount-rules') ?></label>
324
- <select class="product_list selectpicker" multiple name="product_based_condition[product_to_apply][]">
325
- <?php foreach ($products as $index => $value) { ?>
326
- <option
327
- value="<?php echo $index; ?>" <?php if (in_array($index, $product_based_condition_product_to_apply)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
328
- <?php } ?>
329
- </select>
330
  <label ><?php esc_html_e('Product(s)', 'woo-discount-rules') ?></label>
331
  </div>
332
  </div>
@@ -423,13 +404,9 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
423
  <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
424
  <option value="any_cheapest"<?php echo ($discount_product_option == 'any_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest', 'woo-discount-rules') ?></option>
425
  </select>
426
- <select class="product_list selectpicker price_discount_product_list" multiple
427
- name="discount_range[<?php echo $fieldIndex; ?>][discount_product][]">
428
- <?php foreach ($products as $index => $value) { ?>
429
- <option
430
- value="<?php echo $index; ?>" <?php if (in_array($index, $products_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
431
- <?php } ?>
432
- </select>
433
  </div>
434
  </label>
435
 
@@ -471,6 +448,7 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
471
  value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
472
  <input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
473
  <input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
 
474
  </form>
475
  </div>
476
 
153
  </option>
154
  </select>
155
  <div class="form-group" id="product_list">
156
+ <?php $products_list = json_decode((isset($data->product_to_apply) ? $data->product_to_apply : '{}'), true);
157
+ echo FlycartWoocommerceProduct::getProductAjaxSelectBox($products_list, 'product_to_apply');
158
+ ?>
 
 
 
 
 
159
  </div>
160
  <div class="form-group" id="category_list">
161
  <?php $category_list = json_decode((isset($data->category_to_apply) ? $data->category_to_apply : '{}'), true); ?>
198
  </option>
199
  </select>
200
  <div class="form-group" id="user_list">
201
+ <?php $users_list = json_decode((isset($data->users_to_apply) ? $data->users_to_apply : '{}'), true);
202
+ echo FlycartWoocommerceProduct::getUserAjaxSelectBox($users_list, 'users_to_apply');
203
+ ?>
 
 
 
 
204
  </div>
205
  </div>
206
  </div>
305
  <input placeholder="<?php esc_html_e('Quantity', 'woo-discount-rules') ?>" type="text" name="product_based_condition[product_quantity_to]" value="<?php echo $product_based_condition_product_quantity_to; ?>"/ >
306
  </div>
307
  <label ><?php esc_html_e('Product(s) from', 'woo-discount-rules')?></label>
308
+ <?php echo FlycartWoocommerceProduct::getProductAjaxSelectBox($product_based_condition_product_to_buy, 'product_based_condition[product_to_buy]'); ?>
 
 
 
 
 
309
  <label ><?php esc_html_e('and get discount in ', 'woo-discount-rules') ?></label>
310
+ <?php echo FlycartWoocommerceProduct::getProductAjaxSelectBox($product_based_condition_product_to_apply, 'product_based_condition[product_to_apply]'); ?>
 
 
 
 
 
311
  <label ><?php esc_html_e('Product(s)', 'woo-discount-rules') ?></label>
312
  </div>
313
  </div>
404
  <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
405
  <option value="any_cheapest"<?php echo ($discount_product_option == 'any_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest', 'woo-discount-rules') ?></option>
406
  </select>
407
+ <?php
408
+ echo FlycartWoocommerceProduct::getProductAjaxSelectBox($products_list, "discount_range[".$fieldIndex."][discount_product]");
409
+ ?>
 
 
 
 
410
  </div>
411
  </label>
412
 
448
  value="<?php echo admin_url('admin.php?page=woo_discount_rules'); ?>">
449
  <input type="hidden" id="pro_suffix" value="<?php echo $suffix; ?>">
450
  <input type="hidden" id="is_pro" value="<?php echo $pro; ?>">
451
+ <input type="hidden" id="flycart_wdr_woocommerce_version" value="<?php echo $flycart_wdr_woocommerce_version; ?>">
452
  </form>
453
  </div>
454
 
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.35
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.36
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1