Discount Rules for WooCommerce - Version 1.5.0

Version Description

  • 21/02/18 =
  • Feature - Price rule buy from category X and get discount in category Y (Pro)
  • Feature - Cart rule based on shipping state (Pro)
  • Feature - Coupon rule based on coupon applied (Pro)
  • Fix - Not updating the discount price in cart widget for chrome
  • Improvement - Option to enable and disable the strike out price in cart item
Download this release

Release Info

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

Code changes from version 1.4.45 to 1.5.0

assets/css/style.css CHANGED
@@ -42,7 +42,7 @@
42
  font-style: italic;
43
  color: #999;
44
  }
45
- .discount_product_option_list_con, .discount_product_option_more_cheapest_con, .discount_product_percent_con{
46
  display: inline-block;
47
  }
48
  .rule_buttons_con{
42
  font-style: italic;
43
  color: #999;
44
  }
45
+ .discount_product_option_list_con, .discount_product_option_more_cheapest_con, .discount_product_percent_con, .discount_category_option_list_con{
46
  display: inline-block;
47
  }
48
  .rule_buttons_con{
assets/js/app.js CHANGED
@@ -142,7 +142,8 @@ function validateFields(){
142
  '<option value="percentage_discount"> Percentage Discount </option> <option value="price_discount">Price Discount </option> <option value="product_discount">Product Discount </option> </select></label> <label>Value ' +
143
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
144
  form += '<div class="price_discount_product_list_con hide">' +
145
- ' Apply for <select class="selectpicker discount_product_option" name="discount_range['+count+'][discount_product_option]"><option value="all">All selected</option><option value="any_cheapest">Any one cheapest from selected</option><option value="any_cheapest_from_all">Any one cheapest from all products</option><option value="more_than_one_cheapest">More than one cheapest from selected</option><option value="more_than_one_cheapest_from_all">More than one cheapest from all</option>' +
 
146
  '</select>';
147
  form += '<div class="discount_product_option_more_cheapest_con hide">';
148
  form += '<label>Item count<input type="text" name="discount_range['+count+'][discount_product_items]" class="form-control" value="" placeholder="ex. 1" /></label>';
@@ -155,6 +156,14 @@ function validateFields(){
155
  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>'
156
  }
157
  form += '</div>';
 
 
 
 
 
 
 
 
158
  form += '<div class="discount_product_percent_con">';
159
  form += ' and <select class="selectpicker discount_product_discount_type" name="discount_range['+ count +'][discount_product_discount_type]"><option value="">100% percent</option><option value="limited_percent">Limited percent</option></select>';
160
  form += '<label class="discount_product_percent_field"> Percent <input type="text" name="discount_range['+count+'][discount_product_percent]" class="form-control discount_product_percent_field" value="" placeholder="ex. 10" /></label>';
@@ -174,6 +183,7 @@ function validateFields(){
174
  $('#discount_rule_list').append(form);
175
  $('.product_list,.selectpicker').selectpicker('refresh');
176
  $('.wc-product-search').trigger( 'wc-enhanced-select-init' );
 
177
  });
178
 
179
  // Removing Discount Rule.
@@ -317,7 +327,10 @@ function validateFields(){
317
  '<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>' +
318
  '<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup>' +
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){
@@ -343,7 +356,10 @@ function validateFields(){
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" data-live-search="true" 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" data-live-search="true" multiple name="discount_rule[' + count + '][product_to_apply][]"></select></div>' +
@@ -414,17 +430,24 @@ function validateFields(){
414
  //on change discount_product_option in product discount
415
  $(document).on('change', 'select.discount_product_option', function () {
416
  var discount_product = $(this).closest('.price_discount_product_list_con').find('.discount_product_option_list_con');
 
417
  var discount_product_more_cheapest = $(this).closest('.price_discount_product_list_con').find('.discount_product_option_more_cheapest_con');
 
418
  if($(this).val() == 'any_cheapest_from_all' || $(this).val() == 'more_than_one_cheapest_from_all'){
419
  discount_product.addClass('hide');
420
  } else {
421
  discount_product.removeClass('hide');
422
  }
423
- if($(this).val() == 'more_than_one_cheapest' || $(this).val() == 'more_than_one_cheapest_from_all'){
424
  discount_product_more_cheapest.removeClass('hide');
425
  } else {
426
  discount_product_more_cheapest.addClass('hide');
427
  }
 
 
 
 
 
428
  });
429
  $('select.discount_product_option').trigger('change');
430
 
142
  '<option value="percentage_discount"> Percentage Discount </option> <option value="price_discount">Price Discount </option> <option value="product_discount">Product Discount </option> </select></label> <label>Value ' +
143
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
144
  form += '<div class="price_discount_product_list_con hide">' +
145
+ ' Apply for <select class="selectpicker discount_product_option" name="discount_range['+count+'][discount_product_option]"><option value="all">All selected</option><option value="any_cheapest">Any one cheapest from selected</option><option value="any_cheapest_from_all">Any one cheapest from all products</option>' +
146
+ '<option value="more_than_one_cheapest_from_cat">More than one cheapest from selected category</option><option value="more_than_one_cheapest">More than one cheapest from selected</option><option value="more_than_one_cheapest_from_all">More than one cheapest from all</option>' +
147
  '</select>';
148
  form += '<div class="discount_product_option_more_cheapest_con hide">';
149
  form += '<label>Item count<input type="text" name="discount_range['+count+'][discount_product_items]" class="form-control" value="" placeholder="ex. 1" /></label>';
156
  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>'
157
  }
158
  form += '</div>';
159
+ form += '<div class="discount_category_option_list_con hide">';
160
+ form += '<select class="category_list selectpicker" multiple name="discount_range[' + count + '][discount_category][]">';
161
+ $("#category_list select.category_list option").each(function()
162
+ {
163
+ form += '<option value="'+$(this).val()+'">'+$(this).html()+'</option>';
164
+ });
165
+ form += '</select>';
166
+ form += '</div>';
167
  form += '<div class="discount_product_percent_con">';
168
  form += ' and <select class="selectpicker discount_product_discount_type" name="discount_range['+ count +'][discount_product_discount_type]"><option value="">100% percent</option><option value="limited_percent">Limited percent</option></select>';
169
  form += '<label class="discount_product_percent_field"> Percent <input type="text" name="discount_range['+count+'][discount_product_percent]" class="form-control discount_product_percent_field" value="" placeholder="ex. 10" /></label>';
183
  $('#discount_rule_list').append(form);
184
  $('.product_list,.selectpicker').selectpicker('refresh');
185
  $('.wc-product-search').trigger( 'wc-enhanced-select-init' );
186
+ $('select.discount_product_discount_type').trigger('change');
187
  });
188
 
189
  // Removing Discount Rule.
327
  '<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>' +
328
  '<optgroup label="Customer Email Domain (Eg: edu)"><option value="customer_email_tld">Email ends with</option></optgroup>' +
329
  '<optgroup label="Customer Billing Details"><option value="customer_billing_city">Billing city</option></optgroup>' +
330
+ '<optgroup label="Customer Shipping Details"><option value="customer_shipping_state">Shipping state</option></optgroup>' +
331
+ '<optgroup label="Purchase History"><option value="customer_based_on_purchase_history">Based on Purchase history</option></optgroup>' +
332
+ '<optgroup label="Coupon applied"><option value="coupon_applied_any_one">Atleast any one</option><option value="coupon_applied_all_selected">All selected</option></optgroup>' +
333
+ '</select></label></div>' +
334
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
335
  '<div id="user_div_' + count + '">';
336
  if($('#flycart_wdr_woocommerce_version').val() == 2){
356
  '<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>' +
357
  '<optgroup label="Customer Email Domain (Eg: edu)"><option disabled>Email ends with <b>' + pro_suffix + '</b></option></optgroup>' +
358
  '<optgroup label="Customer Billing Details"><option disabled>Billing city <b>' + pro_suffix + '</b></option></optgroup>' +
359
+ '<optgroup label="Customer Shipping Details"><option disabled>Shipping state <b>' + pro_suffix + '</b></option></optgroup>' +
360
+ '<optgroup label="Purchase History"><option disabled>Based on Purchase history <b>' + pro_suffix + '</b></option></optgroup>' +
361
+ '<optgroup label="Coupon applied"><option disabled>Atleast any one <b>' + pro_suffix + '</b></option><option disabled>All selected <b>' + pro_suffix + '</b></option></optgroup>' +
362
+ '</select></label></div>' +
363
  '<div class="col-md-3 form-group"><label> Value<div id="general_' + count + '"><input type="text" name="discount_rule[' + count + '][option_value]"></div>' +
364
  '<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>' +
365
  '<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>' +
430
  //on change discount_product_option in product discount
431
  $(document).on('change', 'select.discount_product_option', function () {
432
  var discount_product = $(this).closest('.price_discount_product_list_con').find('.discount_product_option_list_con');
433
+ var discount_category = $(this).closest('.price_discount_product_list_con').find('.discount_category_option_list_con');
434
  var discount_product_more_cheapest = $(this).closest('.price_discount_product_list_con').find('.discount_product_option_more_cheapest_con');
435
+ discount_category.addClass('hide');
436
  if($(this).val() == 'any_cheapest_from_all' || $(this).val() == 'more_than_one_cheapest_from_all'){
437
  discount_product.addClass('hide');
438
  } else {
439
  discount_product.removeClass('hide');
440
  }
441
+ if($(this).val() == 'more_than_one_cheapest' || $(this).val() == 'more_than_one_cheapest_from_all' || $(this).val() == 'more_than_one_cheapest_from_cat'){
442
  discount_product_more_cheapest.removeClass('hide');
443
  } else {
444
  discount_product_more_cheapest.addClass('hide');
445
  }
446
+ if($(this).val() == 'more_than_one_cheapest_from_cat'){
447
+ discount_product.addClass('hide');
448
+ discount_category.removeClass('hide');
449
+ }
450
+
451
  });
452
  $('select.discount_product_option').trigger('change');
453
 
helper/woo-function.php CHANGED
@@ -288,6 +288,18 @@ if(!class_exists('FlycartWoocommerceProduct')){
288
  return $cat_id;
289
  }
290
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  /*
292
  * Get WooCommerce get product select box
293
  *
@@ -489,6 +501,18 @@ if(!class_exists('FlycartWoocommerceOrder')){
489
  {
490
  return FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_billing_city() : $order->billing_city;
491
  }
 
 
 
 
 
 
 
 
 
 
 
 
492
  }
493
  }
494
 
288
  return $cat_id;
289
  }
290
 
291
+ /**
292
+ * Get category by id
293
+ *
294
+ * @access public
295
+ * @param int $category_id
296
+ * @return string
297
+ */
298
+ public static function get_product_category_by_id( $category_id ) {
299
+ $term = get_term_by( 'id', $category_id, 'product_cat', 'ARRAY_A' );
300
+ return $term['name'];
301
+ }
302
+
303
  /*
304
  * Get WooCommerce get product select box
305
  *
501
  {
502
  return FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_billing_city() : $order->billing_city;
503
  }
504
+
505
+ /**
506
+ * Get order shipping state
507
+ *
508
+ * @access public
509
+ * @param object $order
510
+ * @return float
511
+ */
512
+ public static function get_shipping_state($order)
513
+ {
514
+ return FlycartWoocommerceVersion::wcVersion('3.0') ? $order->get_shipping_state() : $order->shipping_state;
515
+ }
516
  }
517
  }
518
 
includes/cart-rules.php CHANGED
@@ -857,6 +857,47 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
857
  }
858
  return false;
859
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
860
  case 'categories_in':
861
  if(count($rule)){
862
  $ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules);
@@ -875,8 +916,62 @@ if (!class_exists('FlycartWooDiscountRulesCartRules')) {
875
  }
876
  return false;
877
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
878
  }
879
 
 
880
  }
881
 
882
  /**
857
  }
858
  return false;
859
  break;
860
+ case 'customer_shipping_state':
861
+ $rule = explode(',', $rule);
862
+ foreach($rule as $key => $r){
863
+ $rule[$key] = strtolower(trim($r));
864
+ }
865
+ $postData = $this->postData->get('post_data', '', 'raw');
866
+ $postDataArray = array();
867
+ if($postData != ''){
868
+ parse_str($postData, $postDataArray);
869
+ }
870
+ if(isset($postDataArray['ship_to_different_address']) && $postDataArray['ship_to_different_address']){
871
+ $shippingFieldName = 'shipping_state';
872
+ } else {
873
+ $shippingFieldName = 'billing_state';
874
+ }
875
+ $postShippingState = $this->postData->get($shippingFieldName, '', 'raw');
876
+ if($postShippingState != ''){
877
+ $postDataArray[$shippingFieldName] = $postShippingState;
878
+ }
879
+ if(!get_current_user_id()){
880
+ $order_id = $this->postData->get('order-received', 0);
881
+ if($order_id){
882
+ $order = FlycartWoocommerceOrder::wc_get_order($order_id);
883
+ $postDataArray['shipping_state'] = FlycartWoocommerceOrder::get_shipping_state($order);
884
+ }
885
+ }
886
+ if(isset($postDataArray[$shippingFieldName]) && $postDataArray[$shippingFieldName] != ''){
887
+ $shippingState = $postDataArray[$shippingFieldName];
888
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
889
+ return true;
890
+ }
891
+ } else if(get_current_user_id()){
892
+ $shippingState = get_user_meta( get_current_user_id(), 'shipping_state', true );
893
+ if($shippingState != '' && !empty($shippingState)){
894
+ if(in_array(strtolower($shippingState), $rule) || in_array(strtoupper($shippingState), $rule)){
895
+ return true;
896
+ }
897
+ }
898
+ }
899
+ return false;
900
+ break;
901
  case 'categories_in':
902
  if(count($rule)){
903
  $ruleSuccess = $this->validateCartItemsInSelectedCategory($index, $rule, $rules);
916
  }
917
  return false;
918
  break;
919
+ case 'coupon_applied_any_one':
920
+ if(count($rule)){
921
+ $ruleSuccess = $this->validateCartCouponAppliedAnyOne($index, $rule, $rules);
922
+ if($ruleSuccess){
923
+ return true;
924
+ }
925
+ }
926
+ return false;
927
+ break;
928
+ case 'coupon_applied_all_selected':
929
+ if(count($rule)){
930
+ $ruleSuccess = $this->validateCartCouponAppliedAllSelected($index, $rule, $rules);
931
+ if($ruleSuccess){
932
+ return true;
933
+ }
934
+ }
935
+ return false;
936
+ break;
937
+ }
938
+
939
+ }
940
+
941
+ /**
942
+ * check the any one of the selected coupon applied
943
+ * */
944
+ protected function validateCartCouponAppliedAnyOne($index, $rule, $rules){
945
+ global $woocommerce;
946
+ $allowed = 0;
947
+ $coupons = explode(',', $rule);
948
+ foreach ($coupons as $coupon){
949
+ if($woocommerce->cart->has_discount($coupon)){
950
+ $allowed = 1;
951
+ break;
952
+ }
953
+ }
954
+
955
+ return $allowed;
956
+ }
957
+
958
+ /**
959
+ * check the all the selected coupon applied
960
+ * */
961
+ protected function validateCartCouponAppliedAllSelected($index, $rule, $rules){
962
+ global $woocommerce;
963
+ $allowed = 0;
964
+ $coupons = explode(',', $rule);
965
+ foreach ($coupons as $coupon){
966
+ if(!$woocommerce->cart->has_discount($coupon)){
967
+ $allowed = 0;
968
+ break;
969
+ } else {
970
+ $allowed = 1;
971
+ }
972
  }
973
 
974
+ return $allowed;
975
  }
976
 
977
  /**
includes/pricing-rules.php CHANGED
@@ -997,7 +997,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
997
  if(!empty($productCheapest)){
998
  $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
999
  }
1000
- } else if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'more_than_one_cheapest_from_all'){
1001
  $discount_product_items = (isset($range->discount_product_items) ? $range->discount_product_items : 1);
1002
  if($discount_product_items < 1) $discount_product_items = 1;
1003
  $discount_product_qty = (isset($range->discount_product_qty) ? $range->discount_product_qty : 1);
@@ -1037,7 +1037,10 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1037
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'more_than_one_cheapest';
1038
  $adjustment = array();
1039
  $adjustmentValues = array();
1040
- if($discount_product_option == "more_than_one_cheapest_from_all") $productIds = $this->getAllProductsFromCart();
 
 
 
1041
  for ($i = 1; $i <= $discount_item; $i++){
1042
  $productCheapest = $this->getCheapestProductFromCart($productIds, 0, $discount_quantity, $range);
1043
  if(!empty($productCheapest)){
@@ -1069,6 +1072,22 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1069
  return $products;
1070
  }
1071
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1072
  /**
1073
  * Get cheapest product
1074
  * */
@@ -1600,6 +1619,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1600
  $discount_type = isset($value->discount_type) ? $value->discount_type : 0;
1601
  $to_discount = isset($value->to_discount) ? $value->to_discount : 0;
1602
  $product_discount = isset($value->discount_product) ? $value->discount_product : array();
 
1603
  $discount_product_option = isset($value->discount_product_option) ? $value->discount_product_option : 'all';
1604
  $discount_product_discount_type = isset($value->discount_product_discount_type) ? $value->discount_product_discount_type : '';
1605
  $discount_product_percent = isset($value->discount_product_percent) ? $value->discount_product_percent : 0;
@@ -1621,13 +1641,20 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1621
  if($discount_product_option == 'any_cheapest'){
1622
  $htmlProduct .= esc_html__('any cheapest one of ', 'woo-discount-rules');
1623
  }
1624
- if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'more_than_one_cheapest_from_all'){
1625
  $htmlProduct .= $discount_product_qty;
1626
  $htmlProduct .= esc_html__(' quantity of any ', 'woo-discount-rules');
1627
  $htmlProduct .= $discount_product_items;
1628
  $htmlProduct .= esc_html__(' cheapest item ', 'woo-discount-rules');
1629
  }
1630
- if(count($product_discount) && $discount_product_option != 'more_than_one_cheapest_from_all'){
 
 
 
 
 
 
 
1631
  foreach ($product_discount as $product_id){
1632
  $product = FlycartWoocommerceProduct::wc_get_product($product_id);
1633
  $htmlProduct .= "<a href='".FlycartWoocommerceProduct::get_permalink($product)."'>";
@@ -1871,8 +1898,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1871
  */
1872
  public function replaceVisiblePricesCart($item_price, $cart_item = array(), $cart_item_key = null)
1873
  {
1874
-
1875
- if (!isset($cart_item['woo_discount'])) {
 
1876
  return $item_price;
1877
  }
1878
 
@@ -1881,7 +1909,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1881
 
1882
  // Format price to display
1883
  $price_to_display = FlycartWoocommerceProduct::wc_price($price);
1884
- $original_price_to_display = FlycartWoocommerceProduct::wc_price($cart_item['woo_discount']['original_price']);;
1885
 
1886
  if ($cart_item['woo_discount']['original_price'] != $price) {
1887
  $item_price = '<span class="cart_price"><del>' . $original_price_to_display . '</del> <ins>' . $price_to_display . '</ins></span>';
997
  if(!empty($productCheapest)){
998
  $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
999
  }
1000
+ } else if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'more_than_one_cheapest_from_all'|| $discount_product_option == 'more_than_one_cheapest_from_cat'){
1001
  $discount_product_items = (isset($range->discount_product_items) ? $range->discount_product_items : 1);
1002
  if($discount_product_items < 1) $discount_product_items = 1;
1003
  $discount_product_qty = (isset($range->discount_product_qty) ? $range->discount_product_qty : 1);
1037
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'more_than_one_cheapest';
1038
  $adjustment = array();
1039
  $adjustmentValues = array();
1040
+ if($discount_product_option == "more_than_one_cheapest_from_all")
1041
+ $productIds = $this->getAllProductsFromCart();
1042
+ else if($discount_product_option == "more_than_one_cheapest_from_cat")
1043
+ $productIds = $this->getAllProductsFromCartAndSelectedCategory($range->discount_category);
1044
  for ($i = 1; $i <= $discount_item; $i++){
1045
  $productCheapest = $this->getCheapestProductFromCart($productIds, 0, $discount_quantity, $range);
1046
  if(!empty($productCheapest)){
1072
  return $products;
1073
  }
1074
 
1075
+ /**
1076
+ * Get Products from Cart (selected category)
1077
+ * */
1078
+ protected function getAllProductsFromCartAndSelectedCategory($category){
1079
+ $products = array();
1080
+ if(!empty($category) && is_array($category)){
1081
+ $cart = FlycartWoocommerceCart::get_cart();
1082
+ foreach ( $cart as $cart_item ) {
1083
+ $result = $this->isItemInCategoryList($category, $cart_item);
1084
+ if($result) $products[] = $cart_item['product_id'];
1085
+ }
1086
+ }
1087
+
1088
+ return $products;
1089
+ }
1090
+
1091
  /**
1092
  * Get cheapest product
1093
  * */
1619
  $discount_type = isset($value->discount_type) ? $value->discount_type : 0;
1620
  $to_discount = isset($value->to_discount) ? $value->to_discount : 0;
1621
  $product_discount = isset($value->discount_product) ? $value->discount_product : array();
1622
+ $category_discount = isset($value->discount_category) ? $value->discount_category : array();
1623
  $discount_product_option = isset($value->discount_product_option) ? $value->discount_product_option : 'all';
1624
  $discount_product_discount_type = isset($value->discount_product_discount_type) ? $value->discount_product_discount_type : '';
1625
  $discount_product_percent = isset($value->discount_product_percent) ? $value->discount_product_percent : 0;
1641
  if($discount_product_option == 'any_cheapest'){
1642
  $htmlProduct .= esc_html__('any cheapest one of ', 'woo-discount-rules');
1643
  }
1644
+ if($discount_product_option == 'more_than_one_cheapest' || $discount_product_option == 'more_than_one_cheapest_from_all' || $discount_product_option == 'more_than_one_cheapest_from_cat'){
1645
  $htmlProduct .= $discount_product_qty;
1646
  $htmlProduct .= esc_html__(' quantity of any ', 'woo-discount-rules');
1647
  $htmlProduct .= $discount_product_items;
1648
  $htmlProduct .= esc_html__(' cheapest item ', 'woo-discount-rules');
1649
  }
1650
+ if($discount_product_option == 'more_than_one_cheapest_from_cat'){
1651
+ $htmlProduct .= esc_html__('from the category ', 'woo-discount-rules');
1652
+ $htmlCategories = '';
1653
+ foreach ($category_discount as $category_id){
1654
+ $htmlCategories .= FlycartWoocommerceProduct::get_product_category_by_id($category_id).', ';
1655
+ }
1656
+ $htmlProduct .= trim($htmlCategories, ', ');
1657
+ } else if(count($product_discount) && $discount_product_option != 'more_than_one_cheapest_from_all'){
1658
  foreach ($product_discount as $product_id){
1659
  $product = FlycartWoocommerceProduct::wc_get_product($product_id);
1660
  $htmlProduct .= "<a href='".FlycartWoocommerceProduct::get_permalink($product)."'>";
1898
  */
1899
  public function replaceVisiblePricesCart($item_price, $cart_item = array(), $cart_item_key = null)
1900
  {
1901
+ $config = new FlycartWooDiscountBase();
1902
+ $show_strikeout_in_cart = $config->getConfigData('show_strikeout_in_cart', 1);
1903
+ if (!isset($cart_item['woo_discount']) || !$show_strikeout_in_cart) {
1904
  return $item_price;
1905
  }
1906
 
1909
 
1910
  // Format price to display
1911
  $price_to_display = FlycartWoocommerceProduct::wc_price($price);
1912
+ $original_price_to_display = FlycartWoocommerceProduct::wc_price($cart_item['woo_discount']['original_price']);
1913
 
1914
  if ($cart_item['woo_discount']['original_price'] != $price) {
1915
  $item_price = '<span class="cart_price"><del>' . $original_price_to_display . '</del> <ins>' . $price_to_display . '</ins></span>';
loader.php CHANGED
@@ -110,10 +110,24 @@ if(!class_exists('FlycartWooDiscountRules')){
110
  add_action('wp_ajax_RemoveRule', array($this->discountBase, 'removeRule'));
111
  }
112
 
 
 
 
 
 
 
 
 
113
  /**
114
  * Load Admin scripts
115
  * */
116
  protected function loadSiteScripts(){
 
 
 
 
 
 
117
  $postData = \FlycartInput\FInput::getInstance();
118
  // Handling Tight update with wooCommerce Changes.
119
  $empty_add_to_cart = $postData->get('add-to-cart');
@@ -125,7 +139,11 @@ if(!class_exists('FlycartWooDiscountRules')){
125
  } else if (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) {
126
  add_action('woocommerce_after_cart_item_quantity_update', array($this->discountBase, 'handleDiscount'), 100);
127
  } else {
128
- add_action('woocommerce_cart_loaded_from_session', array($this->discountBase, 'handleDiscount'), 100);
 
 
 
 
129
  }
130
 
131
  // Manually Update Line Item Name.
@@ -163,4 +181,6 @@ if(!class_exists('FlycartWooDiscountRules')){
163
  /**
164
  * init Woo Discount Rules
165
  */
166
- FlycartWooDiscountRules::init();
 
 
110
  add_action('wp_ajax_RemoveRule', array($this->discountBase, 'removeRule'));
111
  }
112
 
113
+ /**
114
+ * Apply discount rules
115
+ * */
116
+ public function applyDiscountRules(){
117
+ $this->discountBase->handleDiscount();
118
+ remove_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
119
+ }
120
+
121
  /**
122
  * Load Admin scripts
123
  * */
124
  protected function loadSiteScripts(){
125
+ $woocommerce_version = '2.0.0';
126
+ $pluginDetails = get_plugin_data(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php');
127
+ if(isset($pluginDetails['Version'])){
128
+ $woocommerce_version = $pluginDetails['Version'];
129
+ }
130
+
131
  $postData = \FlycartInput\FInput::getInstance();
132
  // Handling Tight update with wooCommerce Changes.
133
  $empty_add_to_cart = $postData->get('add-to-cart');
139
  } else if (!empty($empty_apply_coupon) || !empty($empty_update_cart) || !empty($empty_proceed)) {
140
  add_action('woocommerce_after_cart_item_quantity_update', array($this->discountBase, 'handleDiscount'), 100);
141
  } else {
142
+ if(version_compare($woocommerce_version, '3.0', '>=')){
143
+ add_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
144
+ } else {
145
+ add_action('woocommerce_cart_loaded_from_session', array($this->discountBase, 'handleDiscount'), 100);
146
+ }
147
  }
148
 
149
  // Manually Update Line Item Name.
181
  /**
182
  * init Woo Discount Rules
183
  */
184
+ if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
185
+ FlycartWooDiscountRules::init();
186
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
- Stable tag: 1.4.45
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -241,6 +241,13 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
241
 
242
  == Changelog ==
243
 
 
 
 
 
 
 
 
244
  = 1.4.45 - 12/02/18 =
245
  * Feature - Option to disable the rules while having coupon(third party) in cart
246
 
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
+ Stable tag: 1.5.0
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
241
 
242
  == Changelog ==
243
 
244
+ = 1.5.0 - 21/02/18 =
245
+ * Feature - Price rule buy from category X and get discount in category Y (Pro)
246
+ * Feature - Cart rule based on shipping state (Pro)
247
+ * Feature - Coupon rule based on coupon applied (Pro)
248
+ * Fix - Not updating the discount price in cart widget for chrome
249
+ * Improvement - Option to enable and disable the strike out price in cart item
250
+
251
  = 1.4.45 - 12/02/18 =
252
  * Feature - Option to disable the rules while having coupon(third party) in cart
253
 
view/settings.php CHANGED
@@ -128,6 +128,18 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
128
  <div class="notice notice-info"><p><?php esc_html_e('It displays only if any rule matches', 'woo-discount-rules'); ?></p></div>
129
  </div>
130
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
131
  <div class="row form-group">
132
  <div class="col-md-2">
133
  <label>
128
  <div class="notice notice-info"><p><?php esc_html_e('It displays only if any rule matches', 'woo-discount-rules'); ?></p></div>
129
  </div>
130
  </div>
131
+ <div class="row form-group">
132
+ <div class="col-md-2">
133
+ <label>
134
+ <?php esc_html_e('Show strikeout discount in cart item', 'woo-discount-rules'); ?>
135
+ </label>
136
+ </div>
137
+ <?php $data['show_strikeout_in_cart'] = (isset($data['show_strikeout_in_cart']) ? $data['show_strikeout_in_cart'] : 1); ?>
138
+ <div class="col-md-6">
139
+ <label><input type="radio" name="show_strikeout_in_cart" value="1" <?php echo ($data['show_strikeout_in_cart'] == 1)? 'checked': '' ?>/> <?php esc_html_e('Yes', 'woo-discount-rules'); ?></label>
140
+ <label><input type="radio" name="show_strikeout_in_cart" value="0" <?php echo ($data['show_strikeout_in_cart'] == 0)? 'checked': '' ?> /> <?php esc_html_e('No', 'woo-discount-rules'); ?></label>
141
+ </div>
142
+ </div>
143
  <div class="row form-group">
144
  <div class="col-md-2">
145
  <label>
view/view-cart-rules.php CHANGED
@@ -256,6 +256,18 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
256
  <?php } ?>
257
  </option>
258
  </optgroup>
 
 
 
 
 
 
 
 
 
 
 
 
259
  <optgroup label="Purchase History">
260
  <option
261
  <?php if (!$pro) { ?> disabled <?php } else { ?> value="customer_based_on_purchase_history" <?php
@@ -268,6 +280,28 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
268
  <?php } ?>
269
  </option>
270
  </optgroup>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  </select>
272
  </label>
273
  </div>
256
  <?php } ?>
257
  </option>
258
  </optgroup>
259
+ <optgroup label="Customer Shipping Details">
260
+ <option
261
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="customer_shipping_state" <?php
262
+ }
263
+ if ($type == 'customer_shipping_state') { ?> selected=selected <?php } ?>>
264
+ <?php if (!$pro) { ?>
265
+ Shipping state <b><?php echo $suffix; ?></b>
266
+ <?php } else { ?>
267
+ Shipping state
268
+ <?php } ?>
269
+ </option>
270
+ </optgroup>
271
  <optgroup label="Purchase History">
272
  <option
273
  <?php if (!$pro) { ?> disabled <?php } else { ?> value="customer_based_on_purchase_history" <?php
280
  <?php } ?>
281
  </option>
282
  </optgroup>
283
+ <optgroup label="Coupon applied">
284
+ <option
285
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="coupon_applied_any_one" <?php
286
+ }
287
+ if ($type == 'coupon_applied_any_one') { ?> selected=selected <?php } ?>>
288
+ <?php if (!$pro) { ?>
289
+ Atleast any one <b><?php echo $suffix; ?></b>
290
+ <?php } else { ?>
291
+ Atleast any one
292
+ <?php } ?>
293
+ </option>
294
+ <option
295
+ <?php if (!$pro) { ?> disabled <?php } else { ?> value="coupon_applied_all_selected" <?php
296
+ }
297
+ if ($type == 'coupon_applied_all_selected') { ?> selected=selected <?php } ?>>
298
+ <?php if (!$pro) { ?>
299
+ All selected <b><?php echo $suffix; ?></b>
300
+ <?php } else { ?>
301
+ All selected
302
+ <?php } ?>
303
+ </option>
304
+ </optgroup>
305
  </select>
306
  </label>
307
  </div>
view/view-pricing-rules.php CHANGED
@@ -420,6 +420,7 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
420
  <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
421
  <option value="any_cheapest"<?php echo ($discount_product_option == 'any_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest from selected', 'woo-discount-rules') ?></option>
422
  <option value="any_cheapest_from_all"<?php echo ($discount_product_option == 'any_cheapest_from_all')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest from all products', 'woo-discount-rules') ?></option>
 
423
  <option value="more_than_one_cheapest"<?php echo ($discount_product_option == 'more_than_one_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('More than one cheapest from selected', 'woo-discount-rules') ?></option>
424
  <option value="more_than_one_cheapest_from_all"<?php echo ($discount_product_option == 'more_than_one_cheapest_from_all')? ' selected="selected"': '' ?>><?php esc_html_e('More than one cheapest from all', 'woo-discount-rules') ?></option>
425
  </select>
@@ -444,6 +445,17 @@ $isPro = (new FlycartWooDiscountRulesPurchase())->isPro();
444
  echo FlycartWoocommerceProduct::getProductAjaxSelectBox($products_list, "discount_range[".$fieldIndex."][discount_product]");
445
  ?>
446
  </div>
 
 
 
 
 
 
 
 
 
 
 
447
  <div class="discount_product_percent_con hide">
448
  <?php
449
  $discount_product_discount_type = (isset($discount->discount_product_discount_type) ? $discount->discount_product_discount_type : '');
420
  <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
421
  <option value="any_cheapest"<?php echo ($discount_product_option == 'any_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest from selected', 'woo-discount-rules') ?></option>
422
  <option value="any_cheapest_from_all"<?php echo ($discount_product_option == 'any_cheapest_from_all')? ' selected="selected"': '' ?>><?php esc_html_e('Any one cheapest from all products', 'woo-discount-rules') ?></option>
423
+ <option value="more_than_one_cheapest_from_cat"<?php echo ($discount_product_option == 'more_than_one_cheapest_from_cat')? ' selected="selected"': '' ?>><?php esc_html_e('More than one cheapest from selected category', 'woo-discount-rules') ?></option>
424
  <option value="more_than_one_cheapest"<?php echo ($discount_product_option == 'more_than_one_cheapest')? ' selected="selected"': '' ?>><?php esc_html_e('More than one cheapest from selected', 'woo-discount-rules') ?></option>
425
  <option value="more_than_one_cheapest_from_all"<?php echo ($discount_product_option == 'more_than_one_cheapest_from_all')? ' selected="selected"': '' ?>><?php esc_html_e('More than one cheapest from all', 'woo-discount-rules') ?></option>
426
  </select>
445
  echo FlycartWoocommerceProduct::getProductAjaxSelectBox($products_list, "discount_range[".$fieldIndex."][discount_product]");
446
  ?>
447
  </div>
448
+ <div class="discount_category_option_list_con hide">
449
+ <?php
450
+ $discount_category_selected = (isset($discount->discount_category) ? $discount->discount_category : array());
451
+ ?>
452
+ <select class="category_list selectpicker" multiple
453
+ name="<?php echo "discount_range[".$fieldIndex."][discount_category][]"; ?>">
454
+ <?php foreach ($category as $index => $value) { ?>
455
+ <option value="<?php echo $index; ?>"<?php if (in_array($index, $discount_category_selected)) { ?> selected=selected <?php } ?>><?php echo $value; ?></option>
456
+ <?php } ?>
457
+ </select>
458
+ </div>
459
  <div class="discount_product_percent_con hide">
460
  <?php
461
  $discount_product_discount_type = (isset($discount->discount_product_discount_type) ? $discount->discount_product_discount_type : '');
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.45
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1
@@ -17,4 +17,4 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
17
 
18
  include_once('helper/activation-helper.php');
19
 
20
- include_once('loader.php');
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.5.0
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1
17
 
18
  include_once('helper/activation-helper.php');
19
 
20
+ include_once('loader.php');