Discount Rules for WooCommerce - Version 1.4.24

Version Description

  • 13/11/17 =
  • Feature Show discount price in product page
  • Feature Discount based on Purchase history for pro version
Download this release

Release Info

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

Code changes from version 1.4.23 to 1.4.24

assets/css/style.css CHANGED
@@ -27,4 +27,8 @@
27
  }
28
  .license-success{
29
  color: green;
 
 
 
 
30
  }
27
  }
28
  .license-success{
29
  color: green;
30
+ }
31
+ #based_on_purchase_history_fields{
32
+ margin-top: 10px;
33
+ display: none;
34
  }
assets/js/app.js CHANGED
@@ -308,6 +308,7 @@ function validateFields(){
308
  var category_list = $('#cart_category_list_0 > option').clone();
309
  var roles_list = $('#cart_roles_list_0 > option').clone();
310
  var country_list = $('#cart_countries_list_0 > option').clone();
 
311
  if (is_pro) {
312
  var form = '<div class="cart_rules_list row"> <div class="col-md-3 form-group"> <label>Type <select class="form-control cart_rule_type" id="cart_condition_type_' + count + '" name="discount_rule[' + count + '][type]"> <optgroup label="Cart Subtotal"><option value="subtotal_least" selected="selected">Subtotal at least</option><option value="subtotal_less">Subtotal less than</option></optgroup>' +
313
  '<optgroup label="Cart Item Count"><option value="item_count_least">Count of cart items at least</option><option value="item_count_less">Count of cart items less than</option></optgroup>' +
@@ -319,13 +320,15 @@ function validateFields(){
319
  '</optgroup>' +
320
  '<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>' +
321
  '<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup>' +
322
- '<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup></select></label></div>' +
 
323
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
324
  '<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>' +
325
  '<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>' +
326
  '<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
327
  '<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
328
  '<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
 
329
  '</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
330
  '</label></div>';
331
  } else {
@@ -339,13 +342,15 @@ function validateFields(){
339
  '</optgroup>' +
340
  '<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>' +
341
  '<optgroup label="Customer Email Domain (Eg: edu)"><option disabled>Email ends with <b>' + pro_suffix + '</b></option></optgroup>' +
342
- '<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
 
343
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
344
  '<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>' +
345
  '<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>' +
346
  '<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
347
  '<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
348
  '<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
 
349
  '</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
350
  '</label></div>';
351
  }
@@ -362,6 +367,7 @@ function validateFields(){
362
  $('#cart_category_list_' + count).append(category_list);
363
  $('#cart_roles_list_' + count).append(roles_list);
364
  $('#cart_countries_list_' + count).append(country_list);
 
365
 
366
  // Refresh the SelectPicker.
367
  $('.user_list').selectpicker('refresh');
@@ -369,6 +375,7 @@ function validateFields(){
369
  $('.category_list').selectpicker('refresh');
370
  $('.roles_list').selectpicker('refresh');
371
  $('.country_list').selectpicker('refresh');
 
372
 
373
  // Default Hide List.
374
  $('#user_div_' + count).css('display', 'none');
@@ -376,6 +383,7 @@ function validateFields(){
376
  $('#category_div_' + count).css('display', 'none');
377
  $('#roles_div_' + count).css('display', 'none');
378
  $('#countries_div_' + count).css('display', 'none');
 
379
  });
380
 
381
  $(document).on('change', '.cart_rule_type', function () {
@@ -452,6 +460,7 @@ function validateFields(){
452
  $('#cart_category_list_' + id).selectpicker('val', []);
453
  $('#cart_roles_list_' + id).selectpicker('val', []);
454
  $('#cart_countries_list_' + id).selectpicker('val', []);
 
455
 
456
  });
457
 
@@ -511,6 +520,15 @@ function validateFields(){
511
  }
512
  });
513
 
 
 
 
 
 
 
 
 
 
514
  //--------------------------------------------------------------------------------------------------------------
515
  //-----------------------------------------------SETTINGS-------------------------------------------------------
516
  //--------------------------------------------------------------------------------------------------------------
@@ -569,6 +587,7 @@ function validateFields(){
569
  $('#general_' + id).css('display', 'none');
570
  $('#roles_div_' + id).css('display', 'none');
571
  $('#countries_div_' + id).css('display', 'none');
 
572
  } else if (option == 'categories_atleast_one' || option == 'categories_not_in' || option == 'categories_in') {
573
  $('#user_div_' + id).css('display', 'none');
574
  $('#product_div_' + id).css('display', 'none');
@@ -576,6 +595,7 @@ function validateFields(){
576
  $('#general_' + id).css('display', 'none');
577
  $('#roles_div_' + id).css('display', 'none');
578
  $('#countries_div_' + id).css('display', 'none');
 
579
  } else if (option == 'users_in') {
580
  $('#user_div_' + id).css('display', 'block');
581
  $('#product_div_' + id).css('display', 'none');
@@ -583,6 +603,7 @@ function validateFields(){
583
  $('#general_' + id).css('display', 'none');
584
  $('#roles_div_' + id).css('display', 'none');
585
  $('#countries_div_' + id).css('display', 'none');
 
586
  } else if (option == 'roles_in') {
587
  $('#user_div_' + id).css('display', 'none');
588
  $('#product_div_' + id).css('display', 'none');
@@ -590,6 +611,7 @@ function validateFields(){
590
  $('#general_' + id).css('display', 'none');
591
  $('#roles_div_' + id).css('display', 'block');
592
  $('#countries_div_' + id).css('display', 'none');
 
593
  } else if (option == 'shipping_countries_in') {
594
  $('#user_div_' + id).css('display', 'none');
595
  $('#product_div_' + id).css('display', 'none');
@@ -597,6 +619,15 @@ function validateFields(){
597
  $('#general_' + id).css('display', 'none');
598
  $('#roles_div_' + id).css('display', 'none');
599
  $('#countries_div_' + id).css('display', 'block');
 
 
 
 
 
 
 
 
 
600
  } else {
601
  $('#user_div_' + id).css('display', 'none');
602
  $('#product_div_' + id).css('display', 'none');
@@ -604,6 +635,7 @@ function validateFields(){
604
  $('#general_' + id).css('display', 'block');
605
  $('#roles_div_' + id).css('display', 'none');
606
  $('#countries_div_' + id).css('display', 'none');
 
607
  }
608
 
609
  }
308
  var category_list = $('#cart_category_list_0 > option').clone();
309
  var roles_list = $('#cart_roles_list_0 > option').clone();
310
  var country_list = $('#cart_countries_list_0 > option').clone();
311
+ var order_status_list = $('#order_status_list_0 > option').clone();
312
  if (is_pro) {
313
  var form = '<div class="cart_rules_list row"> <div class="col-md-3 form-group"> <label>Type <select class="form-control cart_rule_type" id="cart_condition_type_' + count + '" name="discount_rule[' + count + '][type]"> <optgroup label="Cart Subtotal"><option value="subtotal_least" selected="selected">Subtotal at least</option><option value="subtotal_less">Subtotal less than</option></optgroup>' +
314
  '<optgroup label="Cart Item Count"><option value="item_count_least">Count of cart items at least</option><option value="item_count_less">Count of cart items less than</option></optgroup>' +
320
  '</optgroup>' +
321
  '<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>' +
322
  '<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup>' +
323
+ '<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup>' +
324
+ '<optgroup label="Purchase History"><option value="customer_based_on_purchase_history">Based on Purchase history</option></optgroup></select></label></div>' +
325
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
326
  '<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>' +
327
  '<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>' +
328
  '<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
329
  '<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
330
  '<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
331
+ '<div id="purchase_history_div_' + count + '">Total purchased amount at least <input name="discount_rule[' + count + '][purchased_history_amount]" value="" type="text"/> In Order status <select id="order_status_list_' + count + '" class="order_status_list selectpicker" multiple name="discount_rule[' + count + '][purchase_history_order_status][]"></select></div>' +
332
  '</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
333
  '</label></div>';
334
  } else {
342
  '</optgroup>' +
343
  '<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>' +
344
  '<optgroup label="Customer Email Domain (Eg: edu)"><option disabled>Email ends with <b>' + pro_suffix + '</b></option></optgroup>' +
345
+ '<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup>' +
346
+ '<optgroup label="Purchase History"><option disabled>Based on Purchase history <b>' + pro_suffix + '</b></option></optgroup></select></label></div>' +
347
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
348
  '<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>' +
349
  '<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>' +
350
  '<div id="category_div_' + count + '"><select id="cart_category_list_' + count + '" class="category_list selectpicker" multiple name="discount_rule[' + count + '][category_to_apply][]"></select></div>' +
351
  '<div id="roles_div_' + count + '"><select id="cart_roles_list_' + count + '" class="roles_list selectpicker" multiple name="discount_rule[' + count + '][user_roles_to_apply][]"></select></div>' +
352
  '<div id="countries_div_' + count + '"><select id="cart_countries_list_' + count + '" class="country_list selectpicker" multiple name="discount_rule[' + count + '][countries_to_apply][]"></select></div>' +
353
+ '<div id="purchase_history_div_' + count + '"><select id="order_status_list_' + count + '" class="order_status_list selectpicker" multiple name="discount_rule[' + count + '][purchase_history_order_status][]"></select></div>' +
354
  '</div><div class="col-md-1"> <label> Action <a href=javascript:void(0) class="button button-secondary remove_cart_rule">Remove</a> </label> </div>' +
355
  '</label></div>';
356
  }
367
  $('#cart_category_list_' + count).append(category_list);
368
  $('#cart_roles_list_' + count).append(roles_list);
369
  $('#cart_countries_list_' + count).append(country_list);
370
+ $('#order_status_list_' + count).append(order_status_list);
371
 
372
  // Refresh the SelectPicker.
373
  $('.user_list').selectpicker('refresh');
375
  $('.category_list').selectpicker('refresh');
376
  $('.roles_list').selectpicker('refresh');
377
  $('.country_list').selectpicker('refresh');
378
+ $('.order_status_list').selectpicker('refresh');
379
 
380
  // Default Hide List.
381
  $('#user_div_' + count).css('display', 'none');
383
  $('#category_div_' + count).css('display', 'none');
384
  $('#roles_div_' + count).css('display', 'none');
385
  $('#countries_div_' + count).css('display', 'none');
386
+ $('#purchase_history_div_' + count).css('display', 'none');
387
  });
388
 
389
  $(document).on('change', '.cart_rule_type', function () {
460
  $('#cart_category_list_' + id).selectpicker('val', []);
461
  $('#cart_roles_list_' + id).selectpicker('val', []);
462
  $('#cart_countries_list_' + id).selectpicker('val', []);
463
+ $('#order_status_list_' + id).selectpicker('val', []);
464
 
465
  });
466
 
520
  }
521
  });
522
 
523
+ $('#based_on_purchase_history').on('change', function () {
524
+ var checked = $( "input#based_on_purchase_history:checked" ).length;
525
+ if(checked){
526
+ $('#based_on_purchase_history_fields').show();
527
+ } else {
528
+ $('#based_on_purchase_history_fields').hide();
529
+ }
530
+ });
531
+ $('#based_on_purchase_history').trigger('change');
532
  //--------------------------------------------------------------------------------------------------------------
533
  //-----------------------------------------------SETTINGS-------------------------------------------------------
534
  //--------------------------------------------------------------------------------------------------------------
587
  $('#general_' + id).css('display', 'none');
588
  $('#roles_div_' + id).css('display', 'none');
589
  $('#countries_div_' + id).css('display', 'none');
590
+ $('#purchase_history_div_' + id).css('display', 'none');
591
  } else if (option == 'categories_atleast_one' || option == 'categories_not_in' || option == 'categories_in') {
592
  $('#user_div_' + id).css('display', 'none');
593
  $('#product_div_' + id).css('display', 'none');
595
  $('#general_' + id).css('display', 'none');
596
  $('#roles_div_' + id).css('display', 'none');
597
  $('#countries_div_' + id).css('display', 'none');
598
+ $('#purchase_history_div_' + id).css('display', 'none');
599
  } else if (option == 'users_in') {
600
  $('#user_div_' + id).css('display', 'block');
601
  $('#product_div_' + id).css('display', 'none');
603
  $('#general_' + id).css('display', 'none');
604
  $('#roles_div_' + id).css('display', 'none');
605
  $('#countries_div_' + id).css('display', 'none');
606
+ $('#purchase_history_div_' + id).css('display', 'none');
607
  } else if (option == 'roles_in') {
608
  $('#user_div_' + id).css('display', 'none');
609
  $('#product_div_' + id).css('display', 'none');
611
  $('#general_' + id).css('display', 'none');
612
  $('#roles_div_' + id).css('display', 'block');
613
  $('#countries_div_' + id).css('display', 'none');
614
+ $('#purchase_history_div_' + id).css('display', 'none');
615
  } else if (option == 'shipping_countries_in') {
616
  $('#user_div_' + id).css('display', 'none');
617
  $('#product_div_' + id).css('display', 'none');
619
  $('#general_' + id).css('display', 'none');
620
  $('#roles_div_' + id).css('display', 'none');
621
  $('#countries_div_' + id).css('display', 'block');
622
+ $('#purchase_history_div_' + id).css('display', 'none');
623
+ } else if (option == 'customer_based_on_purchase_history') {
624
+ $('#user_div_' + id).css('display', 'none');
625
+ $('#product_div_' + id).css('display', 'none');
626
+ $('#category_div_' + id).css('display', 'none');
627
+ $('#general_' + id).css('display', 'none');
628
+ $('#roles_div_' + id).css('display', 'none');
629
+ $('#countries_div_' + id).css('display', 'none');
630
+ $('#purchase_history_div_' + id).css('display', 'block');
631
  } else {
632
  $('#user_div_' + id).css('display', 'none');
633
  $('#product_div_' + id).css('display', 'none');
635
  $('#general_' + id).css('display', 'block');
636
  $('#roles_div_' + id).css('display', 'none');
637
  $('#countries_div_' + id).css('display', 'none');
638
+ $('#purchase_history_div_' + id).css('display', 'none');
639
  }
640
 
641
  }
includes/cart-rules-3.php CHANGED
@@ -150,7 +150,6 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
150
  $id = wp_insert_post($post);
151
  $request['status'] = 'publish';
152
  }
153
-
154
  foreach ($request['discount_rule'] as $index => $value) {
155
  $request['discount_rule'][$index] = woo_dicount_rules_generalHelper::makeString($value);
156
  }
@@ -879,6 +878,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
879
  }
880
  return false;
881
  break;
 
 
 
 
 
 
 
 
 
882
  /*case 'categories_atleast_one':
883
  if(count($rule)){
884
  $w_categories = $this->getCartProductCaregories();
@@ -897,6 +905,41 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
897
 
898
  }
899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
900
  /**
901
  * verify the cart items are from selected category
902
  * */
150
  $id = wp_insert_post($post);
151
  $request['status'] = 'publish';
152
  }
 
153
  foreach ($request['discount_rule'] as $index => $value) {
154
  $request['discount_rule'][$index] = woo_dicount_rules_generalHelper::makeString($value);
155
  }
878
  }
879
  return false;
880
  break;
881
+ case 'customer_based_on_purchase_history':
882
+ if(count($rule)){
883
+ $ruleSuccess = $this->validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules);
884
+ if($ruleSuccess){
885
+ return true;
886
+ }
887
+ }
888
+ return false;
889
+ break;
890
  /*case 'categories_atleast_one':
891
  if(count($rule)){
892
  $w_categories = $this->getCartProductCaregories();
905
 
906
  }
907
 
908
+ /**
909
+ * check the cart items satisfies purchase history rule
910
+ * */
911
+ protected function validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules){
912
+ $allowed = 0;
913
+ $user = get_current_user_id();
914
+ if($user){
915
+ if(isset($rule['purchase_history_order_status']) && isset($rule['purchased_history_amount'])){
916
+ if($rule['purchased_history_amount'] > 0){
917
+ $purchase_history_status_list = isset($rule['purchase_history_order_status'])? $rule['purchase_history_order_status']: array('wc-completed');
918
+ $customerOrders = get_posts( array(
919
+ 'numberposts' => -1,
920
+ 'meta_key' => '_customer_user',
921
+ 'meta_value' => $user,
922
+ 'post_type' => wc_get_order_types(),
923
+ 'post_status' => $purchase_history_status_list,
924
+ ) );
925
+ $totalPurchasedAmount = 0;
926
+ if(!empty($customerOrders)){
927
+ foreach ($customerOrders as $customerOrder) {
928
+ $order = wc_get_order($customerOrder->ID);
929
+ $total = $order->get_total();
930
+ $totalPurchasedAmount += $total;
931
+ }
932
+ }
933
+ if($totalPurchasedAmount >= $rule['purchased_history_amount']){
934
+ $allowed = 1;
935
+ }
936
+ }
937
+ }
938
+ }
939
+
940
+ return $allowed;
941
+ }
942
+
943
  /**
944
  * verify the cart items are from selected category
945
  * */
includes/cart-rules.php CHANGED
@@ -881,6 +881,15 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
881
  }
882
  return false;
883
  break;
 
 
 
 
 
 
 
 
 
884
  /*case 'categories_atleast_one':
885
  if(count($rule)){
886
  $w_categories = $this->getCartProductCaregories();
@@ -899,6 +908,41 @@ if (!class_exists('woo_dicount_rules_cartRules')) {
899
 
900
  }
901
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
902
  /**
903
  * verify the cart items are from selected category
904
  * */
881
  }
882
  return false;
883
  break;
884
+ case 'customer_based_on_purchase_history':
885
+ if(count($rule)){
886
+ $ruleSuccess = $this->validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules);
887
+ if($ruleSuccess){
888
+ return true;
889
+ }
890
+ }
891
+ return false;
892
+ break;
893
  /*case 'categories_atleast_one':
894
  if(count($rule)){
895
  $w_categories = $this->getCartProductCaregories();
908
 
909
  }
910
 
911
+ /**
912
+ * check the cart items satisfies purchase history rule
913
+ * */
914
+ protected function validateCartItemsBasedOnPurchaseHistory($index, $rule, $rules){
915
+ $allowed = 0;
916
+ $user = get_current_user_id();
917
+ if($user){
918
+ if(isset($rule['purchase_history_order_status']) && isset($rule['purchased_history_amount'])){
919
+ if($rule['purchased_history_amount'] > 0){
920
+ $purchase_history_status_list = isset($rule['purchase_history_order_status'])? $rule['purchase_history_order_status']: array('wc-completed');
921
+ $customerOrders = get_posts( array(
922
+ 'numberposts' => -1,
923
+ 'meta_key' => '_customer_user',
924
+ 'meta_value' => $user,
925
+ 'post_type' => wc_get_order_types(),
926
+ 'post_status' => $purchase_history_status_list,
927
+ ) );
928
+ $totalPurchasedAmount = 0;
929
+ if(!empty($customerOrders)){
930
+ foreach ($customerOrders as $customerOrder) {
931
+ $order = wc_get_order($customerOrder->ID);
932
+ $total = $order->get_total();
933
+ $totalPurchasedAmount += $total;
934
+ }
935
+ }
936
+ if($totalPurchasedAmount >= $rule['purchased_history_amount']){
937
+ $allowed = 1;
938
+ }
939
+ }
940
+ }
941
+ }
942
+
943
+ return $allowed;
944
+ }
945
+
946
  /**
947
  * verify the cart items are from selected category
948
  * */
includes/discount-base.php CHANGED
@@ -240,7 +240,11 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
240
  // $link[$value['type']] will gives the native index of the "type"
241
 
242
  if (isset($link[$value['type']])) {
243
- if (isset($value[$link[$value['type']]])) {
 
 
 
 
244
  $discount_list[$index][$value['type']] = $value[$link[$value['type']]];
245
  }
246
  } else {
@@ -268,7 +272,8 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
268
 
269
  'users_in' => 'users_to_apply',
270
  'roles_in' => 'user_roles_to_apply',
271
- 'shipping_countries_in' => 'countries_to_apply'
 
272
  );
273
  }
274
 
240
  // $link[$value['type']] will gives the native index of the "type"
241
 
242
  if (isset($link[$value['type']])) {
243
+ if(is_array($link[$value['type']])){
244
+ foreach ($link[$value['type']] as $fields){
245
+ $discount_list[$index][$value['type']][$fields] = $value[$fields];
246
+ }
247
+ } else if (isset($value[$link[$value['type']]])) {
248
  $discount_list[$index][$value['type']] = $value[$link[$value['type']]];
249
  }
250
  } else {
272
 
273
  'users_in' => 'users_to_apply',
274
  'roles_in' => 'user_roles_to_apply',
275
+ 'shipping_countries_in' => 'countries_to_apply',
276
+ 'customer_based_on_purchase_history' => array('purchase_history_order_status', 'purchased_history_amount')
277
  );
278
  }
279
 
includes/pricing-rules-3.php CHANGED
@@ -84,12 +84,6 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
84
  */
85
  public function save($request)
86
  {
87
- // var_dump($request);
88
- // die();
89
- // foreach ($request as $index => $value) {
90
- // $request[$index] = $value;
91
- // }
92
-
93
  $id = (isset($request['rule_id']) ? $request['rule_id'] : false);
94
 
95
  $id = intval($id);
@@ -185,6 +179,18 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
185
  $form[] = $apply_to;
186
 
187
  if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
 
 
 
 
 
 
 
 
 
 
 
 
188
  //----------------------------------------------------------------------------------------------------------
189
 
190
  // Manage list of Discount Ranges.
@@ -496,6 +502,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
496
  $rule_sets[$index]['qty_based_on'] = (isset($rule->qty_based_on) ? $rule->qty_based_on : 'each_product');
497
  $rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
498
  $rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
 
499
 
500
  // List the type of apply, by Product or by Category.
501
  if (isset($rule->apply_to)) {
@@ -543,16 +550,62 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
543
  }
544
  }
545
  $rule_sets[$index]['apply_to'] = $rule->apply_to;
 
 
 
 
 
546
  }
547
 
548
  // If Current Customer is not Allowed to use this discount, then it's going to be removed.
549
  if ($rule_sets[$index]['allow']['users'] == 'no') {
550
  unset($rule_sets[$index]);
551
  }
 
 
 
 
 
552
  }
553
  $this->rule_sets = $rule_sets;
554
  }
555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  /**
557
  * Get all sub categories
558
  * */
@@ -1328,5 +1381,125 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
1328
 
1329
  return $item_price;
1330
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1331
  }
1332
  }
84
  */
85
  public function save($request)
86
  {
 
 
 
 
 
 
87
  $id = (isset($request['rule_id']) ? $request['rule_id'] : false);
88
 
89
  $id = intval($id);
179
  $form[] = $apply_to;
180
 
181
  if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
182
+
183
+ $based_on_purchase_history = 0;
184
+ if (isset($request['based_on_purchase_history'])) $based_on_purchase_history = $request['based_on_purchase_history'];
185
+ $request['based_on_purchase_history'] = $based_on_purchase_history;
186
+ $form[] = 'based_on_purchase_history';
187
+ if($based_on_purchase_history){
188
+ $form[] = 'purchased_history_amount';
189
+ $form[] = 'purchase_history_status_list';
190
+ if (isset($request['purchase_history_status_list'])) $request['purchase_history_status_list'] = json_encode($request['purchase_history_status_list']);
191
+ else $request['purchase_history_status_list'] = json_encode(array('wc-completed'));
192
+ }
193
+
194
  //----------------------------------------------------------------------------------------------------------
195
 
196
  // Manage list of Discount Ranges.
502
  $rule_sets[$index]['qty_based_on'] = (isset($rule->qty_based_on) ? $rule->qty_based_on : 'each_product');
503
  $rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
504
  $rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
505
+ $rule_sets[$index]['allow']['purchase_history'] = 'yes';
506
 
507
  // List the type of apply, by Product or by Category.
508
  if (isset($rule->apply_to)) {
550
  }
551
  }
552
  $rule_sets[$index]['apply_to'] = $rule->apply_to;
553
+
554
+ // Default setup for purchase history
555
+ if(isset($rule->based_on_purchase_history) && $rule->based_on_purchase_history){
556
+ $rule_sets[$index]['allow']['purchase_history'] = $this->checkWithUsersPurchaseHistory($rule, $woocommerce);
557
+ }
558
  }
559
 
560
  // If Current Customer is not Allowed to use this discount, then it's going to be removed.
561
  if ($rule_sets[$index]['allow']['users'] == 'no') {
562
  unset($rule_sets[$index]);
563
  }
564
+
565
+ // If Current Customer is not Allowed based on purchase history to use this discount, then it's going to be removed.
566
+ if ($rule_sets[$index]['allow']['purchase_history'] == 'no') {
567
+ unset($rule_sets[$index]);
568
+ }
569
  }
570
  $this->rule_sets = $rule_sets;
571
  }
572
 
573
+ /**
574
+ * Check with users purchase history
575
+ * */
576
+ public function checkWithUsersPurchaseHistory($rule, $woocommerce)
577
+ {
578
+ $allowed = 'no';
579
+ $user = get_current_user_id();
580
+ if($user){
581
+ if(isset($rule->purchased_history_amount) && isset($rule->purchase_history_status_list)){
582
+ if($rule->purchased_history_amount > 0){
583
+ $purchase_history_status_list = json_decode($rule->purchase_history_status_list, true);
584
+ $customerOrders = get_posts( array(
585
+ 'numberposts' => -1,
586
+ 'meta_key' => '_customer_user',
587
+ 'meta_value' => $user,
588
+ 'post_type' => wc_get_order_types(),
589
+ 'post_status' => $purchase_history_status_list,
590
+ ) );
591
+ $totalPurchasedAmount = 0;
592
+ if(!empty($customerOrders)){
593
+ foreach ($customerOrders as $customerOrder) {
594
+ $order = wc_get_order($customerOrder->ID);
595
+ $total = $order->get_total();
596
+ $totalPurchasedAmount += $total;
597
+ }
598
+ }
599
+ if($totalPurchasedAmount >= $rule->purchased_history_amount){
600
+ $allowed = 'yes';
601
+ }
602
+ }
603
+ }
604
+ }
605
+
606
+ return $allowed;
607
+ }
608
+
609
  /**
610
  * Get all sub categories
611
  * */
1381
 
1382
  return $item_price;
1383
  }
1384
+
1385
+ /**
1386
+ * Replace visible price if rule matches for variants
1387
+ * */
1388
+ public function replaceVisiblePricesForVariant($data, $product, $variations)
1389
+ {
1390
+ $item_price = $data['price_html'];
1391
+
1392
+ $config = new woo_dicount_rules_WooDiscountBase();
1393
+ $config = $config->getBaseConfig();
1394
+ if (is_string($config)) $config = json_decode($config, true);
1395
+ if(isset($config['price_setup'])){
1396
+ $type = $config['price_setup'];
1397
+ } else {
1398
+ $type = 'all';
1399
+ }
1400
+ $notAdmin = !is_admin();
1401
+ if(isset($config['show_price_discount_on_product_page'])){
1402
+ $show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
1403
+ } else {
1404
+ $show_price_discount_on_product_page = 'dont';
1405
+ }
1406
+ if($show_price_discount_on_product_page == 'show' && $notAdmin){
1407
+ $product_id = $product->get_id();
1408
+ $item['product_id'] = $product_id;
1409
+ $item['data'] = $product;
1410
+ $item['quantity'] = 1;
1411
+ global $woocommerce;
1412
+ $this->analyse($woocommerce);
1413
+ $this->matchRules($product_id, $item);
1414
+
1415
+ if(isset($this->matched_sets[$product_id])){
1416
+ $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type, $variations->get_price());
1417
+ if($discountPrice > 0){
1418
+ $price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($discountPrice) : woocommerce_price($discountPrice);
1419
+ $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins>';
1420
+ }
1421
+ }
1422
+ }
1423
+
1424
+ $data['price_html'] = $item_price;
1425
+ return $data;
1426
+ }
1427
+
1428
+ /**
1429
+ * Replace visible price if rule matches
1430
+ * */
1431
+ public function replaceVisiblePrices($item_price, $product)
1432
+ {
1433
+ // Get settings
1434
+ $config = new woo_dicount_rules_WooDiscountBase();
1435
+ $config = $config->getBaseConfig();
1436
+ if (is_string($config)) $config = json_decode($config, true);
1437
+ if(isset($config['price_setup'])){
1438
+ $type = $config['price_setup'];
1439
+ } else {
1440
+ $type = 'all';
1441
+ }
1442
+ $notAdmin = !is_admin();
1443
+ if(isset($config['show_price_discount_on_product_page'])){
1444
+ $show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
1445
+ } else {
1446
+ $show_price_discount_on_product_page = 'dont';
1447
+ }
1448
+ if($show_price_discount_on_product_page == 'show' && $notAdmin){
1449
+ $product_id = $product->get_id();
1450
+ $item['product_id'] = $product_id;
1451
+ $item['data'] = $product;
1452
+ $item['quantity'] = 1;
1453
+ global $woocommerce;
1454
+ $this->analyse($woocommerce);
1455
+ $this->matchRules($product_id, $item);
1456
+
1457
+ if(isset($this->matched_sets[$product_id])){
1458
+ $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type);
1459
+ if($discountPrice > 0){
1460
+ $price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($discountPrice) : woocommerce_price($discountPrice);
1461
+ $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins></span>';
1462
+ }
1463
+ }
1464
+ }
1465
+
1466
+ return $item_price;
1467
+ }
1468
+
1469
+ /**
1470
+ * get discounted value
1471
+ * */
1472
+ public function getAdjustmentDiscountedPrice($cart_item, $cart_item_key, $type, $price = 0)
1473
+ {
1474
+ // All Sets are Collected properly, just process with that.
1475
+ if (!isset($cart_item)) return false;
1476
+
1477
+ // If Product having the rule sets then,
1478
+ if (!isset($this->matched_sets[$cart_item_key])) return false;
1479
+
1480
+ $adjustment_set = $this->matched_sets[$cart_item_key];
1481
+ if(!($price > 0)){
1482
+ $price = $cart_item->get_price();
1483
+ }
1484
+
1485
+ $amount = 0;
1486
+ $discount = 0;
1487
+ if ($type == 'first') {
1488
+ // For Apply the First Rule.
1489
+ $discount = $this->getAmount($adjustment_set, $price, 'first');
1490
+
1491
+ } else if ($type == 'biggest') {
1492
+ // For Apply the Biggest Discount.
1493
+ $discount = $this->getAmount($adjustment_set, $price, 'biggest');
1494
+ } else {
1495
+ // For Apply All Rules.
1496
+ $discount = $this->getAmount($adjustment_set, $price);
1497
+ }
1498
+ if($discount > 0){
1499
+ $amount = $price - $discount;
1500
+ }
1501
+
1502
+ return $amount;
1503
+ }
1504
  }
1505
  }
includes/pricing-rules.php CHANGED
@@ -84,12 +84,6 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
84
  */
85
  public function save($request)
86
  {
87
- // var_dump($request);
88
- // die();
89
- // foreach ($request as $index => $value) {
90
- // $request[$index] = $value;
91
- // }
92
-
93
  $id = (isset($request['rule_id']) ? $request['rule_id'] : false);
94
 
95
  $id = intval($id);
@@ -172,6 +166,18 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
172
  $form[] = $apply_to;
173
 
174
  if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
 
 
 
 
 
 
 
 
 
 
 
 
175
  //----------------------------------------------------------------------------------------------------------
176
 
177
  // Manage Users.
@@ -496,6 +502,7 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
496
  $rule_sets[$index]['qty_based_on'] = (isset($rule->qty_based_on) ? $rule->qty_based_on : 'each_product');
497
  $rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
498
  $rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
 
499
 
500
  // List the type of apply, by Product or by Category.
501
  if (isset($rule->apply_to)) {
@@ -543,12 +550,22 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
543
  }
544
  }
545
  $rule_sets[$index]['apply_to'] = $rule->apply_to;
 
 
 
 
 
546
  }
547
 
548
  // If Current Customer is not Allowed to use this discount, then it's going to be removed.
549
  if ($rule_sets[$index]['allow']['users'] == 'no') {
550
  unset($rule_sets[$index]);
551
  }
 
 
 
 
 
552
  }
553
  $this->rule_sets = $rule_sets;
554
  }
@@ -1324,5 +1341,125 @@ if (!class_exists('woo_dicount_rules_pricingRules')) {
1324
 
1325
  return $item_price;
1326
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1327
  }
1328
  }
84
  */
85
  public function save($request)
86
  {
 
 
 
 
 
 
87
  $id = (isset($request['rule_id']) ? $request['rule_id'] : false);
88
 
89
  $id = intval($id);
166
  $form[] = $apply_to;
167
 
168
  if (isset($request[$apply_to])) $request[$apply_to] = json_encode($request[$apply_to]);
169
+
170
+ $based_on_purchase_history = 0;
171
+ if (isset($request['based_on_purchase_history'])) $based_on_purchase_history = $request['based_on_purchase_history'];
172
+ $request['based_on_purchase_history'] = $based_on_purchase_history;
173
+ $form[] = 'based_on_purchase_history';
174
+ if($based_on_purchase_history){
175
+ $form[] = 'purchased_history_amount';
176
+ $form[] = 'purchase_history_status_list';
177
+ if (isset($request['purchase_history_status_list'])) $request['purchase_history_status_list'] = json_encode($request['purchase_history_status_list']);
178
+ else $request['purchase_history_status_list'] = json_encode(array('wc-completed'));
179
+ }
180
+
181
  //----------------------------------------------------------------------------------------------------------
182
 
183
  // Manage Users.
502
  $rule_sets[$index]['qty_based_on'] = (isset($rule->qty_based_on) ? $rule->qty_based_on : 'each_product');
503
  $rule_sets[$index]['date_from'] = (isset($rule->date_from) ? $rule->date_from : false);
504
  $rule_sets[$index]['date_to'] = (isset($rule->date_to) ? $rule->date_to : false);
505
+ $rule_sets[$index]['allow']['purchase_history'] = 'yes';
506
 
507
  // List the type of apply, by Product or by Category.
508
  if (isset($rule->apply_to)) {
550
  }
551
  }
552
  $rule_sets[$index]['apply_to'] = $rule->apply_to;
553
+
554
+ // Default setup for purchase history
555
+ if(isset($rule->based_on_purchase_history) && $rule->based_on_purchase_history){
556
+ $rule_sets[$index]['allow']['purchase_history'] = $this->checkWithUsersPurchaseHistory($rule, $woocommerce);
557
+ }
558
  }
559
 
560
  // If Current Customer is not Allowed to use this discount, then it's going to be removed.
561
  if ($rule_sets[$index]['allow']['users'] == 'no') {
562
  unset($rule_sets[$index]);
563
  }
564
+
565
+ // If Current Customer is not Allowed based on purchase history to use this discount, then it's going to be removed.
566
+ if ($rule_sets[$index]['allow']['purchase_history'] == 'no') {
567
+ unset($rule_sets[$index]);
568
+ }
569
  }
570
  $this->rule_sets = $rule_sets;
571
  }
1341
 
1342
  return $item_price;
1343
  }
1344
+
1345
+ /**
1346
+ * Replace visible price if rule matches for variants
1347
+ * */
1348
+ public function replaceVisiblePricesForVariant($data, $product, $variations)
1349
+ {
1350
+ $item_price = $data['price_html'];
1351
+
1352
+ $config = new woo_dicount_rules_WooDiscountBase();
1353
+ $config = $config->getBaseConfig();
1354
+ if (is_string($config)) $config = json_decode($config, true);
1355
+ if(isset($config['price_setup'])){
1356
+ $type = $config['price_setup'];
1357
+ } else {
1358
+ $type = 'all';
1359
+ }
1360
+ $notAdmin = !is_admin();
1361
+ if(isset($config['show_price_discount_on_product_page'])){
1362
+ $show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
1363
+ } else {
1364
+ $show_price_discount_on_product_page = 'dont';
1365
+ }
1366
+ if($show_price_discount_on_product_page == 'show' && $notAdmin){
1367
+ $product_id = $product->id;
1368
+ $item['product_id'] = $product_id;
1369
+ $item['data'] = $product;
1370
+ $item['quantity'] = 1;
1371
+ global $woocommerce;
1372
+ $this->analyse($woocommerce);
1373
+ $this->matchRules($product_id, $item);
1374
+
1375
+ if(isset($this->matched_sets[$product_id])){
1376
+ $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type, $variations->price);
1377
+ if($discountPrice > 0){
1378
+ $price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($discountPrice) : woocommerce_price($discountPrice);
1379
+ $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins>';
1380
+ }
1381
+ }
1382
+ }
1383
+
1384
+ $data['price_html'] = $item_price;
1385
+ return $data;
1386
+ }
1387
+
1388
+ /**
1389
+ * Replace visible price if rule matches
1390
+ * */
1391
+ public function replaceVisiblePrices($item_price, $product)
1392
+ {
1393
+ // Get settings
1394
+ $config = new woo_dicount_rules_WooDiscountBase();
1395
+ $config = $config->getBaseConfig();
1396
+ if (is_string($config)) $config = json_decode($config, true);
1397
+ if(isset($config['price_setup'])){
1398
+ $type = $config['price_setup'];
1399
+ } else {
1400
+ $type = 'all';
1401
+ }
1402
+ $notAdmin = !is_admin();
1403
+ if(isset($config['show_price_discount_on_product_page'])){
1404
+ $show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
1405
+ } else {
1406
+ $show_price_discount_on_product_page = 'dont';
1407
+ }
1408
+ if($show_price_discount_on_product_page == 'show' && $notAdmin){
1409
+ $product_id = $product->id;
1410
+ $item['product_id'] = $product_id;
1411
+ $item['data'] = $product;
1412
+ $item['quantity'] = 1;
1413
+ global $woocommerce;
1414
+ $this->analyse($woocommerce);
1415
+ $this->matchRules($product_id, $item);
1416
+
1417
+ if(isset($this->matched_sets[$product_id])){
1418
+ $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type);
1419
+ if($discountPrice > 0){
1420
+ $price_to_display = woo_dicount_rules_generalHelper::wcVersion('2.1') ? wc_price($discountPrice) : woocommerce_price($discountPrice);
1421
+ $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display) . '</ins></span>';
1422
+ }
1423
+ }
1424
+ }
1425
+
1426
+ return $item_price;
1427
+ }
1428
+
1429
+ /**
1430
+ * get discounted value
1431
+ * */
1432
+ public function getAdjustmentDiscountedPrice($cart_item, $cart_item_key, $type, $price = 0)
1433
+ {
1434
+ // All Sets are Collected properly, just process with that.
1435
+ if (!isset($cart_item)) return false;
1436
+
1437
+ // If Product having the rule sets then,
1438
+ if (!isset($this->matched_sets[$cart_item_key])) return false;
1439
+
1440
+ $adjustment_set = $this->matched_sets[$cart_item_key];
1441
+ if(!($price > 0)){
1442
+ $price = $cart_item->price;
1443
+ }
1444
+
1445
+ $amount = 0;
1446
+ $discount = 0;
1447
+ if ($type == 'first') {
1448
+ // For Apply the First Rule.
1449
+ $discount = $this->getAmount($adjustment_set, $price, 'first');
1450
+
1451
+ } else if ($type == 'biggest') {
1452
+ // For Apply the Biggest Discount.
1453
+ $discount = $this->getAmount($adjustment_set, $price, 'biggest');
1454
+ } else {
1455
+ // For Apply All Rules.
1456
+ $discount = $this->getAmount($adjustment_set, $price);
1457
+ }
1458
+ if($discount > 0){
1459
+ $amount = $price - $discount;
1460
+ }
1461
+
1462
+ return $amount;
1463
+ }
1464
  }
1465
  }
loader.php CHANGED
@@ -140,6 +140,13 @@ remove_filter('woocommerce_cart_item_name', 'filter_woocommerce_cart_item_name',
140
 
141
  // Alter the Display Price HTML.
142
  add_filter('woocommerce_cart_item_price', array($pricingRules, 'replaceVisiblePricesCart'), 100, 3);
 
 
 
 
 
 
 
143
  // Older Version support this hook.
144
  add_filter('woocommerce_cart_item_price_html', array($pricingRules, 'replaceVisiblePricesCart'), 100, 3);
145
 
140
 
141
  // Alter the Display Price HTML.
142
  add_filter('woocommerce_cart_item_price', array($pricingRules, 'replaceVisiblePricesCart'), 100, 3);
143
+
144
+ //replace visible price in product page
145
+ add_filter('woocommerce_get_price_html', array($pricingRules, 'replaceVisiblePrices'), 100, 3);
146
+ //replace visible price in product page for variant
147
+ add_filter('woocommerce_available_variation', array($pricingRules, 'replaceVisiblePricesForVariant'), 100, 3);
148
+
149
+
150
  // Older Version support this hook.
151
  add_filter('woocommerce_cart_item_price_html', array($pricingRules, 'replaceVisiblePricesCart'), 100, 3);
152
 
readme.txt CHANGED
@@ -3,18 +3,26 @@ 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.8.1
7
- Stable tag: 1.4.23
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 discount and pricing rules in your WooCommerce store. Increase your sales multifold by offering flexible, customised discounts and free products to your customers. Encourage your customers to purchase more by providing bulk discounts.
 
 
15
 
16
  [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/6-wordpress-plugins) | [PRO version](https://www.flycart.org/products/wordpress/woocommerce-discount-rules)
17
 
 
 
 
 
 
 
18
  = Use cases =
19
 
20
  * Buy 5 items and get 10 % discount - [Video](https://www.youtube.com/watch?v=84VL6Wwf1DI&t=15s)
@@ -41,6 +49,7 @@ WooCommerce discount rules helps you to create any type of discount and pricing
41
  Conditions can be based products, categories, customers, customer roles, shipping location and more.
42
 
43
  * All products
 
44
  * Specific products / Selected products
45
  * All categories ([PRO feature](https://www.flycart.org/products/wordpress/woocommerce-discount-rules))
46
  * Selected categories ([PRO feature](https://www.flycart.org/products/wordpress/woocommerce-discount-rules))
@@ -103,6 +112,10 @@ More information could be found in the documentation
103
 
104
  Yes. It is possible to create multiple discount and you can setup any number of discount rules in your store.
105
 
 
 
 
 
106
  = Will the discount be showed in the invoice ? =
107
 
108
  Yes. The discount will be displayed separately in the invoice.
@@ -163,6 +176,10 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
163
 
164
  == Changelog ==
165
 
 
 
 
 
166
  = 1.4.23 - 07/11/17 =
167
  * Fix – Notices occur while having pricing rules based on categories due to woocommerce 3.x
168
  * Fix – Removed percentage symbol for fixed pricing discount in pricing table
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.8.3
7
+ Stable tag: 1.4.24
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
 
18
  [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/6-wordpress-plugins) | [PRO version](https://www.flycart.org/products/wordpress/woocommerce-discount-rules)
19
 
20
+ = Discount Types =
21
+
22
+ * Percentage based Discount
23
+ * Price based Discount
24
+ * BOGO deals (Buy 1 get 1 free discounts)
25
+
26
  = Use cases =
27
 
28
  * Buy 5 items and get 10 % discount - [Video](https://www.youtube.com/watch?v=84VL6Wwf1DI&t=15s)
49
  Conditions can be based products, categories, customers, customer roles, shipping location and more.
50
 
51
  * All products
52
+ * Customer purchase history
53
  * Specific products / Selected products
54
  * All categories ([PRO feature](https://www.flycart.org/products/wordpress/woocommerce-discount-rules))
55
  * Selected categories ([PRO feature](https://www.flycart.org/products/wordpress/woocommerce-discount-rules))
112
 
113
  Yes. It is possible to create multiple discount and you can setup any number of discount rules in your store.
114
 
115
+ = Are the discounts visible in Product page ? =
116
+
117
+ Yes. The discount will be displayed in Product page, product details page, cart striking out the Original price.
118
+
119
  = Will the discount be showed in the invoice ? =
120
 
121
  Yes. The discount will be displayed separately in the invoice.
176
 
177
  == Changelog ==
178
 
179
+ = 1.4.24 - 13/11/17 =
180
+ * Feature – Show discount price in product page
181
+ * Feature – Discount based on Purchase history for pro version
182
+
183
  = 1.4.23 - 07/11/17 =
184
  * Fix – Notices occur while having pricing rules based on categories due to woocommerce 3.x
185
  * Fix – Removed percentage symbol for fixed pricing discount in pricing table
view/settings.php CHANGED
@@ -19,14 +19,14 @@ if (is_string($data)) $data = json_decode($data, true);
19
  </div>
20
  <div class="">
21
  <div class="">
22
- <h4>General Settings</h4>
23
  <hr>
24
  </div>
25
  <div class="">
26
  <div class="row form-group">
27
  <div class="col-md-2">
28
  <label>
29
- License Key :
30
  </label>
31
  </div>
32
  <div class="col-md-6">
@@ -44,7 +44,7 @@ if (is_string($data)) $data = json_decode($data, true);
44
  } else {
45
  ?>
46
  <div class="license-failed notice-message error inline notice-error notice-alt">
47
- License key seems to be Invalid. Please enter a valid license key
48
  </div>
49
  <?php
50
  }
@@ -60,61 +60,80 @@ if (is_string($data)) $data = json_decode($data, true);
60
  <?php $data['price_setup'] = (isset($data['price_setup']) ? $data['price_setup'] : 'first'); ?>
61
  <div class="col-md-2">
62
  <label>
63
- Rule Setup for Price:
64
  </label>
65
  </div>
66
  <div class="col-md-6">
67
  <select class="selectpicker" name="price_setup">
68
  <option <?php if ($data['price_setup'] == 'first') { ?> selected=selected <?php } ?>
69
- value="first" selected="selected">Apply first matched rule
70
  </option>
71
  <option
72
  value="all" <?php if (!$pro) { ?> disabled <?php }
73
  if ($data['price_setup'] == 'all') { ?> selected=selected <?php } ?>>
74
  <?php if (!$pro) { ?>
75
- Apply all matched rules <b><?php echo $suffix; ?></b>
76
  <?php } else { ?>
77
- Apply all matched rules
78
  <?php } ?>
79
  </option>
80
  <option
81
  value="biggest" <?php if (!$pro) { ?> disabled <?php }
82
  if ($data['price_setup'] == 'biggest') { ?> selected=selected <?php } ?>>
83
  <?php if (!$pro) { ?>
84
- Apply biggest discount <b><?php echo $suffix; ?></b>
85
  <?php } else { ?>
86
- Apply biggest discount
87
  <?php } ?>
88
  </option>
89
  </select>
90
  </div>
91
  </div>
92
  <div class="row form-group">
 
93
  <div class="col-md-2">
94
  <label>
95
- Discount Title :
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  </label>
97
  </div>
98
  <div class="col-md-6">
99
  <input type="text" class="" name="coupon_name"
100
  value="<?php if (isset($data['coupon_name'])) echo $data['coupon_name']; ?>"
101
- placeholder="Discount Coupon Name">
102
  </div>
103
  </div>
104
  <div class="row form-group">
105
  <?php $data['show_discount_table'] = (isset($data['show_discount_table']) ? $data['show_discount_table'] : 'show'); ?>
106
  <div class="col-md-2">
107
  <label>
108
- Discount Table :
109
  </label>
110
  </div>
111
  <div class="col-md-6">
112
  <select class="selectpicker" name="show_discount_table">
113
  <option <?php if ($data['show_discount_table'] == 'show') { ?> selected=selected <?php } ?>
114
- value="show">Show
115
  </option>
116
  <option <?php if ($data['show_discount_table'] == 'dont') { ?> selected=selected <?php } ?>
117
- value="dont">Don't Show
118
  </option>
119
  </select>
120
  </div>
@@ -123,16 +142,16 @@ if (is_string($data)) $data = json_decode($data, true);
123
  <?php $data['show_discount_title_table'] = (isset($data['show_discount_title_table']) ? $data['show_discount_title_table'] : 'show'); ?>
124
  <div class="col-md-2">
125
  <label>
126
- Show Discount Title on Table :
127
  </label>
128
  </div>
129
  <div class="col-md-6">
130
  <select class="selectpicker" name="show_discount_title_table">
131
  <option <?php if ($data['show_discount_title_table'] == 'show') { ?> selected=selected <?php } ?>
132
- value="show">Show
133
  </option>
134
  <option <?php if ($data['show_discount_title_table'] == 'dont') { ?> selected=selected <?php } ?>
135
- value="dont">Don't Show
136
  </option>
137
  </select>
138
  </div>
@@ -141,30 +160,30 @@ if (is_string($data)) $data = json_decode($data, true);
141
  <?php $data['cart_setup'] = (isset($data['cart_setup']) ? $data['cart_setup'] : 'first'); ?>
142
  <div class="col-md-2">
143
  <label>
144
- Rule Setup for Cart:
145
  </label>
146
  </div>
147
  <div class="col-md-6">
148
  <select class="selectpicker" name="cart_setup">
149
  <option <?php if ($data['cart_setup'] == 'first') { ?> selected=selected <?php } ?>
150
- value="first" selected="selected">Apply first matched rule
151
  </option>
152
  <option
153
  value="all" <?php if (!$pro) { ?> disabled <?php }
154
  if ($data['cart_setup'] == 'all') { ?> selected=selected <?php } ?>>
155
  <?php if (!$pro) { ?>
156
- Apply all matched rules <b><?php echo $suffix; ?></b>
157
  <?php } else { ?>
158
- Apply all matched rules
159
  <?php } ?>
160
  </option>
161
  <option
162
  value="biggest" <?php if (!$pro) { ?> disabled <?php }
163
  if ($data['cart_setup'] == 'biggest') { ?> selected=selected <?php } ?>>
164
  <?php if (!$pro) { ?>
165
- Apply biggest discount <b><?php echo $suffix; ?></b>
166
  <?php } else { ?>
167
- Apply biggest discount
168
  <?php } ?>
169
  </option>
170
  </select>
@@ -173,7 +192,7 @@ if (is_string($data)) $data = json_decode($data, true);
173
  <div class="row form-group">
174
  <div class="col-md-2">
175
  <label>
176
- Draft
177
  </label>
178
  </div>
179
  <div class="col-md-6">
@@ -183,7 +202,7 @@ if (is_string($data)) $data = json_decode($data, true);
183
  $checked = 1;
184
  } ?>
185
  <input type="checkbox" class="" id="show_draft_1" name="show_draft"
186
- value="1" <?php if($checked){ echo 'checked'; } ?>> <label class="checkbox_label" for="show_draft_1">Exclude Draft products in product select box.</label>
187
  </div>
188
  </div>
189
  </div>
19
  </div>
20
  <div class="">
21
  <div class="">
22
+ <h4><?php esc_html_e('General Settings', 'woo-discount-rules'); ?></h4>
23
  <hr>
24
  </div>
25
  <div class="">
26
  <div class="row form-group">
27
  <div class="col-md-2">
28
  <label>
29
+ <?php esc_html_e('License Key :', 'woo-discount-rules'); ?>
30
  </label>
31
  </div>
32
  <div class="col-md-6">
44
  } else {
45
  ?>
46
  <div class="license-failed notice-message error inline notice-error notice-alt">
47
+ <?php esc_html_e('License key seems to be Invalid. Please enter a valid license key', 'woo-discount-rules'); ?>
48
  </div>
49
  <?php
50
  }
60
  <?php $data['price_setup'] = (isset($data['price_setup']) ? $data['price_setup'] : 'first'); ?>
61
  <div class="col-md-2">
62
  <label>
63
+ <?php esc_html_e('Rule Setup for Price:', 'woo-discount-rules'); ?>
64
  </label>
65
  </div>
66
  <div class="col-md-6">
67
  <select class="selectpicker" name="price_setup">
68
  <option <?php if ($data['price_setup'] == 'first') { ?> selected=selected <?php } ?>
69
+ value="first" selected="selected"><?php esc_html_e('Apply first matched rule', 'woo-discount-rules'); ?>
70
  </option>
71
  <option
72
  value="all" <?php if (!$pro) { ?> disabled <?php }
73
  if ($data['price_setup'] == 'all') { ?> selected=selected <?php } ?>>
74
  <?php if (!$pro) { ?>
75
+ <?php esc_html_e('Apply all matched rules', 'woo-discount-rules'); ?> <b><?php echo $suffix; ?></b>
76
  <?php } else { ?>
77
+ <?php esc_html_e('Apply all matched rules', 'woo-discount-rules'); ?>
78
  <?php } ?>
79
  </option>
80
  <option
81
  value="biggest" <?php if (!$pro) { ?> disabled <?php }
82
  if ($data['price_setup'] == 'biggest') { ?> selected=selected <?php } ?>>
83
  <?php if (!$pro) { ?>
84
+ <?php esc_html_e('Apply biggest discount', 'woo-discount-rules'); ?> <b><?php echo $suffix; ?></b>
85
  <?php } else { ?>
86
+ <?php esc_html_e('Apply biggest discount', 'woo-discount-rules'); ?>
87
  <?php } ?>
88
  </option>
89
  </select>
90
  </div>
91
  </div>
92
  <div class="row form-group">
93
+ <?php $data['show_price_discount_on_product_page'] = (isset($data['show_price_discount_on_product_page']) ? $data['show_price_discount_on_product_page'] : 'dont'); ?>
94
  <div class="col-md-2">
95
  <label>
96
+ <?php esc_html_e('Show Price discount on product page :', 'woo-discount-rules'); ?>
97
+ </label>
98
+ </div>
99
+ <div class="col-md-6">
100
+ <select class="selectpicker" name="show_price_discount_on_product_page">
101
+ <option <?php if ($data['show_price_discount_on_product_page'] == 'show') { ?> selected=selected <?php } ?>
102
+ value="show"><?php esc_html_e('Show', 'woo-discount-rules'); ?>
103
+ </option>
104
+ <option <?php if ($data['show_price_discount_on_product_page'] == 'dont') { ?> selected=selected <?php } ?>
105
+ value="dont"><?php esc_html_e('Don\'t Show', 'woo-discount-rules'); ?>
106
+ </option>
107
+ </select>
108
+ <div class="notice notice-info"><p><?php esc_html_e('It displays only if any rule matches based on single quantity', 'woo-discount-rules'); ?></p></div>
109
+ </div>
110
+ </div>
111
+ <div class="row form-group">
112
+ <div class="col-md-2">
113
+ <label>
114
+ <?php esc_html_e('Discount Title :', 'woo-discount-rules'); ?>
115
  </label>
116
  </div>
117
  <div class="col-md-6">
118
  <input type="text" class="" name="coupon_name"
119
  value="<?php if (isset($data['coupon_name'])) echo $data['coupon_name']; ?>"
120
+ placeholder="<?php esc_html_e('Discount Coupon Name', 'woo-discount-rules'); ?>">
121
  </div>
122
  </div>
123
  <div class="row form-group">
124
  <?php $data['show_discount_table'] = (isset($data['show_discount_table']) ? $data['show_discount_table'] : 'show'); ?>
125
  <div class="col-md-2">
126
  <label>
127
+ <?php esc_html_e('Discount Table :', 'woo-discount-rules'); ?>
128
  </label>
129
  </div>
130
  <div class="col-md-6">
131
  <select class="selectpicker" name="show_discount_table">
132
  <option <?php if ($data['show_discount_table'] == 'show') { ?> selected=selected <?php } ?>
133
+ value="show"><?php esc_html_e('Show', 'woo-discount-rules'); ?>
134
  </option>
135
  <option <?php if ($data['show_discount_table'] == 'dont') { ?> selected=selected <?php } ?>
136
+ value="dont"><?php esc_html_e('Don\'t Show', 'woo-discount-rules'); ?>
137
  </option>
138
  </select>
139
  </div>
142
  <?php $data['show_discount_title_table'] = (isset($data['show_discount_title_table']) ? $data['show_discount_title_table'] : 'show'); ?>
143
  <div class="col-md-2">
144
  <label>
145
+ <?php esc_html_e('Show Discount Title on Table :', 'woo-discount-rules'); ?>
146
  </label>
147
  </div>
148
  <div class="col-md-6">
149
  <select class="selectpicker" name="show_discount_title_table">
150
  <option <?php if ($data['show_discount_title_table'] == 'show') { ?> selected=selected <?php } ?>
151
+ value="show"><?php esc_html_e('Show', 'woo-discount-rules'); ?>
152
  </option>
153
  <option <?php if ($data['show_discount_title_table'] == 'dont') { ?> selected=selected <?php } ?>
154
+ value="dont"><?php esc_html_e('Don\'t Show', 'woo-discount-rules'); ?>
155
  </option>
156
  </select>
157
  </div>
160
  <?php $data['cart_setup'] = (isset($data['cart_setup']) ? $data['cart_setup'] : 'first'); ?>
161
  <div class="col-md-2">
162
  <label>
163
+ <?php esc_html_e('Rule Setup for Cart:', 'woo-discount-rules'); ?>
164
  </label>
165
  </div>
166
  <div class="col-md-6">
167
  <select class="selectpicker" name="cart_setup">
168
  <option <?php if ($data['cart_setup'] == 'first') { ?> selected=selected <?php } ?>
169
+ value="first" selected="selected"><?php esc_html_e('Apply first matched rule', 'woo-discount-rules'); ?>
170
  </option>
171
  <option
172
  value="all" <?php if (!$pro) { ?> disabled <?php }
173
  if ($data['cart_setup'] == 'all') { ?> selected=selected <?php } ?>>
174
  <?php if (!$pro) { ?>
175
+ <?php esc_html_e('Apply all matched rules', 'woo-discount-rules'); ?> <b><?php echo $suffix; ?></b>
176
  <?php } else { ?>
177
+ <?php esc_html_e('Apply all matched rules', 'woo-discount-rules'); ?>
178
  <?php } ?>
179
  </option>
180
  <option
181
  value="biggest" <?php if (!$pro) { ?> disabled <?php }
182
  if ($data['cart_setup'] == 'biggest') { ?> selected=selected <?php } ?>>
183
  <?php if (!$pro) { ?>
184
+ <?php esc_html_e('Apply biggest discount', 'woo-discount-rules'); ?> <b><?php echo $suffix; ?></b>
185
  <?php } else { ?>
186
+ <?php esc_html_e('Apply biggest discount', 'woo-discount-rules'); ?>
187
  <?php } ?>
188
  </option>
189
  </select>
192
  <div class="row form-group">
193
  <div class="col-md-2">
194
  <label>
195
+ <?php esc_html_e('Draft', 'woo-discount-rules'); ?>
196
  </label>
197
  </div>
198
  <div class="col-md-6">
202
  $checked = 1;
203
  } ?>
204
  <input type="checkbox" class="" id="show_draft_1" name="show_draft"
205
+ value="1" <?php if($checked){ echo 'checked'; } ?>> <label class="checkbox_label" for="show_draft_1"><?php esc_html_e('Exclude Draft products in product select box.', 'woo-discount-rules'); ?></label>
206
  </div>
207
  </div>
208
  </div>
view/view-cart-rules.php CHANGED
@@ -295,6 +295,18 @@ if (empty($discount_rules)) {
295
  <?php } ?>
296
  </option>
297
  </optgroup>
 
 
 
 
 
 
 
 
 
 
 
 
298
  </select>
299
  </label>
300
  </div>
@@ -368,7 +380,7 @@ if (empty($discount_rules)) {
368
  $roles_list = array();
369
  $class = 'style="display:none"';
370
  if ($type == 'roles_in') {
371
- $roles_list = $discount_rules[$type];;
372
  $class = 'style="display:block"';
373
  $hit = true;
374
  }
@@ -388,7 +400,7 @@ if (empty($discount_rules)) {
388
  $countries_list = array();
389
  $class = 'style="display:none"';
390
  if ($type == 'shipping_countries_in') {
391
- $countries_list = $discount_rules[$type];;
392
  $class = 'style="display:block"';
393
  $hit = true;
394
  }
@@ -407,6 +419,35 @@ if (empty($discount_rules)) {
407
  </select>
408
  </div>
409
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  if ($hit) {
411
  $class = 'style="display:none"';
412
  } else {
295
  <?php } ?>
296
  </option>
297
  </optgroup>
298
+ <optgroup label="Purchase History">
299
+ <option
300
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="customer_based_on_purchase_history" <?php
301
+ }
302
+ if ($type == 'customer_based_on_purchase_history') { ?> selected=selected <?php } ?>>
303
+ <?php if (!$pro) { ?>
304
+ Based on Purchase history <b><?php echo $suffix; ?></b>
305
+ <?php } else { ?>
306
+ Based on Purchase history
307
+ <?php } ?>
308
+ </option>
309
+ </optgroup>
310
  </select>
311
  </label>
312
  </div>
380
  $roles_list = array();
381
  $class = 'style="display:none"';
382
  if ($type == 'roles_in') {
383
+ $roles_list = $discount_rules[$type];
384
  $class = 'style="display:block"';
385
  $hit = true;
386
  }
400
  $countries_list = array();
401
  $class = 'style="display:none"';
402
  if ($type == 'shipping_countries_in') {
403
+ $countries_list = $discount_rules[$type];
404
  $class = 'style="display:block"';
405
  $hit = true;
406
  }
419
  </select>
420
  </div>
421
  <?php
422
+ $order_status_list = array();
423
+ $class = 'style="display:none"';
424
+ $woocommerce_order_status = wc_get_order_statuses();
425
+ if ($type == 'customer_based_on_purchase_history') {
426
+ $purchase_history_status_list = isset($discount_rules[$type]['purchase_history_order_status'])? $discount_rules[$type]['purchase_history_order_status'] : array();
427
+ $purchased_history_amount = isset($discount_rules[$type]['purchased_history_amount'])? $discount_rules[$type]['purchased_history_amount'] : 0;
428
+ if(empty($purchase_history_status_list)){
429
+ $purchase_history_status_list[] = 'wc-completed';
430
+ }
431
+ $class = 'style="display:block"';
432
+ $hit = true;
433
+ }
434
+
435
+ ?>
436
+ <div id="purchase_history_div_<?php echo $i; ?>" <?php echo $class; ?>>
437
+ Total purchased amount at least
438
+ <input name="discount_rule[<?php echo $i; ?>][purchased_history_amount]" value="<?php echo $purchased_history_amount; ?>" type="text"/> In Order status
439
+ <select class="order_status_list selectpicker"
440
+ data-live-search="true"
441
+ id="order_status_list_<?php echo $i; ?>"
442
+ multiple
443
+ name="discount_rule[<?php echo $i; ?>][purchase_history_order_status][]">
444
+ <?php foreach ($woocommerce_order_status as $index => $woocommerce_order_sts) { ?>
445
+ <option
446
+ value="<?php echo $index; ?>"<?php if (in_array($index, $purchase_history_status_list)) { ?> selected=selected <?php } ?>><?php echo $woocommerce_order_sts; ?></option>
447
+ <?php } ?>
448
+ </select>
449
+ </div>
450
+ <?php
451
  if ($hit) {
452
  $class = 'style="display:none"';
453
  } else {
view/view-pricing-rules.php CHANGED
@@ -220,13 +220,46 @@ $rule_id = (isset($data->ID)) ? $data->ID : 0;
220
  </div>
221
  </div>
222
  </div>
223
- <div align="right">
224
- <input type="button" class="button button-secondary general_tab" value="Previous">
225
- <input type="button" class="button button-primary discount_tab" value="Next">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  </div>
227
  </div>
228
  </div>
229
-
230
  <!-- TODO: Implement ForEach Concept -->
231
  <div class="col-md-12" id="discount_block"><h4 class="text text-muted"> Discount</h4>
232
  <a href=javascript:void(0) class="button button-primary" id="addNewDiscountRange"><i
220
  </div>
221
  </div>
222
  </div>
223
+ </div>
224
+ <div class="form-group">
225
+ <div class="row">
226
+ <div class="col-md-3"><label><?php esc_html_e('Purchase History', 'woo-discount-rules'); ?></label></div>
227
+ <?php $based_on_purchase_history = (isset($data->based_on_purchase_history) ? $data->based_on_purchase_history : 0); ?>
228
+ <div class="col-md-6">
229
+ <input type="checkbox" class="" id="based_on_purchase_history" name="based_on_purchase_history"
230
+ value="1" <?php if($based_on_purchase_history){ echo 'checked'; } ?>>
231
+ <label class="checkbox_label" for="based_on_purchase_history"><?php esc_html_e('Yes, based on Purchase history.', 'woo-discount-rules'); ?></label>
232
+ <div class="form-group" id="based_on_purchase_history_fields">
233
+ <?php $purchased_history_amount = (isset($data->purchased_history_amount) ? $data->purchased_history_amount : 0); ?>
234
+ <label><?php esc_html_e('Total purchased amount at least', 'woo-discount-rules'); ?></label>
235
+ <input type="text" value="<?php echo $purchased_history_amount; ?>" name="purchased_history_amount"/>
236
+ <label><?php esc_html_e('In Order status', 'woo-discount-rules'); ?></label>
237
+ <?php
238
+ $woocommerce_order_status = wc_get_order_statuses();
239
+ $purchase_history_status_list = json_decode((isset($data->purchase_history_status_list) ? $data->purchase_history_status_list : '{}'), true);
240
+ if(empty($purchase_history_status_list)){
241
+ $purchase_history_status_list[] = 'wc-completed';
242
+ }
243
+ ?>
244
+ <select class="purchase_history_status_list selectpicker" multiple name="purchase_history_status_list[]">
245
+ <?php foreach ($woocommerce_order_status as $index => $value) { ?>
246
+ <option
247
+ value="<?php echo $index; ?>"<?php if (in_array($index, $purchase_history_status_list)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
248
+ <?php } ?>
249
+ </select>
250
+ </div>
251
+ </div>
252
+ </div>
253
+ </div>
254
+ <div class="form-group">
255
+ <div class="row">
256
+ <div align="right">
257
+ <input type="button" class="button button-secondary general_tab" value="Previous">
258
+ <input type="button" class="button button-primary discount_tab" value="Next">
259
+ </div>
260
  </div>
261
  </div>
262
  </div>
 
263
  <!-- TODO: Implement ForEach Concept -->
264
  <div class="col-md-12" id="discount_block"><h4 class="text text-muted"> Discount</h4>
265
  <a href=javascript:void(0) class="button button-primary" id="addNewDiscountRange"><i
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.23
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.24
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1