Discount Rules for WooCommerce - Version 1.6.4

Version Description

  • 12/06/18 =
  • Improvement - Display table any one of variant attribute/products rule matches
  • Improvement - Display sale tag, if any rule available for that product
  • Fix - Applying discount for duplicate item(same product id and different attributes)
  • Fix - Fatal error while saving rules
Download this release

Release Info

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

Code changes from version 1.6.3 to 1.6.4

helper/general-helper.php CHANGED
@@ -311,13 +311,15 @@ if ( ! class_exists( 'FlycartWooDiscountRulesGeneralHelper' ) ) {
311
  */
312
  static function escapeCode(&$value)
313
  {
314
- // Four Possible tags for PHP to Init.
315
- $value = preg_replace(array('/^<\?php.*\?\>/', '/^<\%.*\%\>/', '/^<\?.*\?\>/', '/^<\?=.*\?\>/'), '', $value);
316
- $value = self::delete_all_between('<?php', '?>', $value);
317
- $value = self::delete_all_between('<?', '?>', $value);
318
- $value = self::delete_all_between('<?=', '?>', $value);
319
- $value = self::delete_all_between('<%', '%>', $value);
320
- $value = str_replace(array('<?php', '<?', '<?=', '<%', '?>'), '', $value);
 
 
321
  }
322
 
323
 
311
  */
312
  static function escapeCode(&$value)
313
  {
314
+ if(is_string($value)){
315
+ // Four Possible tags for PHP to Init.
316
+ $value = preg_replace(array('/^<\?php.*\?\>/', '/^<\%.*\%\>/', '/^<\?.*\?\>/', '/^<\?=.*\?\>/'), '', $value);
317
+ $value = self::delete_all_between('<?php', '?>', $value);
318
+ $value = self::delete_all_between('<?', '?>', $value);
319
+ $value = self::delete_all_between('<?=', '?>', $value);
320
+ $value = self::delete_all_between('<%', '%>', $value);
321
+ $value = str_replace(array('<?php', '<?', '<?=', '<%', '?>'), '', $value);
322
+ }
323
  }
324
 
325
 
helper/woo-function.php CHANGED
@@ -162,6 +162,17 @@ if(!class_exists('FlycartWoocommerceProduct')){
162
  return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_price() : $product->price;
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
165
  /**
166
  * Get WooCommerce product sale price
167
  *
@@ -420,7 +431,10 @@ if(!class_exists('FlycartWoocommerceCartProduct')){
420
  */
421
  public static function get_cart()
422
  {
423
- return WC()->cart->get_cart();
 
 
 
424
  }
425
 
426
  /**
162
  return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_price() : $product->price;
163
  }
164
 
165
+ /**
166
+ * Get WooCommerce product regular price
167
+ *
168
+ * @access public
169
+ * @param array $product
170
+ * @return int/float
171
+ */
172
+ public static function get_regular_price($product){
173
+ return FlycartWoocommerceVersion::wcVersion('3.0') ? $product->get_regular_price() : $product->regular_price;
174
+ }
175
+
176
  /**
177
  * Get WooCommerce product sale price
178
  *
431
  */
432
  public static function get_cart()
433
  {
434
+ if(!empty(WC()->cart)){
435
+ return WC()->cart->get_cart();
436
+ }
437
+ return array();
438
  }
439
 
440
  /**
includes/pricing-rules.php CHANGED
@@ -1106,17 +1106,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1106
 
1107
  case 'all_products':
1108
  default:
1109
- $is_not_in_exclude_sale_items = !$this->isItemInSaleItems($rule['exclude_sale_items'], $item['data']);
1110
- if (!$this->isItemInProductList($rule['product_to_exclude'], $item) && $is_not_in_exclude_sale_items) {
1111
- if(isset($rule['is_cumulative_for_products']) && $rule['is_cumulative_for_products']){
1112
- $totalQuantityFromAllProducts = $this->getProductQuantityForCumulativeProducts($item, $product_page, $rule);
1113
- $quantity = $totalQuantityFromAllProducts;
 
 
 
1114
  }
1115
- $discount_amount = $this->getAdjustmentAmount($item, $quantity, $this->array_first($rule['discount']), $product_page, $bogo);
1116
- $applied_rules[$i] = $this->formatRulesToApply($discount_amount, $rule['name'], $index, $item['product_id'], $id);
1117
- }
1118
 
1119
- break;
1120
  }
1121
  if(isset($applied_rules[$i]['amount']['product_ids'])){
1122
  if(!empty($applied_rules[$i]['amount']['product_ids'])){
@@ -1402,17 +1402,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1402
  $discount_quantity = isset($range->discount_bogo_qty)? $range->discount_bogo_qty: 1000;
1403
  $productCheapest = $this->getCheapestProductFromCart(array($productId), 0, $discount_quantity, $range);
1404
  if(!empty($productCheapest)){
1405
- $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']), 'product_discount_details' => $productCheapest['discount_details']) ;
1406
  }
1407
  } else if($discount_product_option == 'any_cheapest_from_all'){
1408
  $productCheapest = $this->getCheapestProductFromCart($productIds, 1, 1, $range);
1409
  if(!empty($productCheapest)){
1410
- $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
1411
  }
1412
  } else if($discount_product_option == 'any_cheapest'){
1413
  $productCheapest = $this->getCheapestProductFromCart($productIds,0, 1, $range);
1414
  if(!empty($productCheapest)){
1415
- $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
1416
  }
1417
  } 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'){
1418
  $discount_product_items = (isset($range->discount_product_items) ? $range->discount_product_items : 1);
@@ -1496,6 +1496,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1496
  }
1497
  $adjustment['price_discount'] = $productCheapest['percent'];
1498
  $adjustment['product_ids'][] = $productCheapest['product'];
 
1499
  $adjustmentValues[$productCheapest['product']] = $productCheapest['percent'];
1500
  $adjustment['product_discount_adjustment'] = $adjustmentValues;
1501
  $adjustment['product_discount_details'][$productCheapest['product']] = $productCheapest['discount_details'];
@@ -1580,10 +1581,12 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1580
  if($cheapestProductValue == 0){
1581
  $cheapestProductValue = FlycartWoocommerceProduct::get_price($_product);
1582
  $cheapestProduct = FlycartWoocommerceProduct::get_id($_product);
 
1583
  $quantity = $values['quantity'];
1584
  } else if($cheapestProductValue > FlycartWoocommerceProduct::get_price($_product)){
1585
  $cheapestProductValue = FlycartWoocommerceProduct::get_price($_product);
1586
  $cheapestProduct = FlycartWoocommerceProduct::get_id($_product);
 
1587
  $quantity = $values['quantity'];
1588
  }
1589
  }
@@ -1605,7 +1608,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1605
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$quantity));
1606
  else
1607
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$discount_quantity));
1608
- return array('product' => $cheapestProduct, 'percent' => $discount_price, 'discount_details' => $product_discount_details, 'applied_quantity' => $quantity);
1609
  }
1610
  return array();
1611
  }
@@ -2034,6 +2037,11 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2034
  }
2035
  } elseif ($rule->apply_to == 'specific_attribute') {
2036
  $status = false;
 
 
 
 
 
2037
  } else if ($rule->apply_to == 'all_products') {
2038
  $productToExclude = $this->getExcludeProductsFromRule($rule);
2039
  $status = false;
@@ -2099,6 +2107,55 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2099
  return $discount_range;
2100
  }
2101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2102
  /**
2103
  * To get purchased product from rule
2104
  * */
@@ -2158,7 +2215,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2158
  break;
2159
  case 'more':
2160
  default:
2161
- $quantity_text = ' '.$product_quantity_from.esc_html__(' or more Quantity', 'woo-discount-rules');
2162
  }
2163
 
2164
  switch ($product_buy_type) {
@@ -2224,7 +2281,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2224
  $table_data_content = $this->getDiscountTableContentInHTML($table_data, $data);
2225
  include($path);
2226
  //$html = ob_get_contents();
2227
- // ob_clean();
2228
  //ob_get_clean();
2229
  }
2230
 
@@ -2376,7 +2433,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2376
  $price = FlycartWoocommerceProduct::get_price($product);
2377
 
2378
  //To reset the adjustment set if the Product discount adjustment exists
2379
- $adjustment_set = $this->resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_set, $product_id);
2380
  $additionalDetails = array();
2381
 
2382
  if ($type == 'first') {
@@ -2415,10 +2472,16 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2415
  /**
2416
  * To reset the adjustment set if the Product discount adjustment exists
2417
  * */
2418
- protected function resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_sets, $product_id){
2419
  foreach ($adjustment_sets as $key => $adjustment_set){
2420
  if(isset($adjustment_set['amount']['product_discount_adjustment']) && !empty($adjustment_set['amount']['product_discount_adjustment'])){
2421
  if(isset($adjustment_set['amount']['product_discount_adjustment'][$product_id])){
 
 
 
 
 
 
2422
  $adjustment_sets[$key]['amount']['price_discount'] = $adjustment_set['amount']['product_discount_adjustment'][$product_id];
2423
  $adjustment_sets[$key]['amount']['product_ids'] = array($product_id);
2424
  }
@@ -2429,7 +2492,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2429
  }
2430
  }
2431
  }
2432
-
2433
  return $adjustment_sets;
2434
  }
2435
 
@@ -2582,9 +2645,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2582
  $quantity = $cart_item['quantity'];
2583
  foreach ($additional_details as $detail){
2584
  if(isset($detail['discount_quantity']))
2585
- if($detail['discount_quantity'] >= $quantity){
2586
- $run_multiple_strikeout = false;
2587
- }
2588
  }
2589
  return $run_multiple_strikeout;
2590
  }
@@ -2689,7 +2752,6 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2689
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
2690
  $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins>';
2691
  }
2692
-
2693
  }
2694
 
2695
  $data['price_html'] = $item_price;
@@ -2714,6 +2776,19 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2714
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
2715
  $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
2716
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
2717
  }
2718
  }
2719
 
@@ -2784,14 +2859,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2784
  }
2785
  }
2786
  }
2787
-
2788
  return $price_to_display;
2789
  }
2790
 
2791
  /**
2792
  * Display Product sale tag on the product page
2793
  * */
2794
- public function displayProductIsOnSaleTag($on_sale, $product){
2795
  $notAdmin = FlycartWooDiscountRulesGeneralHelper::doIHaveToRun();
2796
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'dont';
2797
  if($show_price_discount_on_product_page == 'show' && $notAdmin){
@@ -2799,6 +2874,38 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2799
  if($discountPrice > 0){
2800
  $on_sale = true;
2801
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2802
  }
2803
  return $on_sale;
2804
  }
@@ -2812,6 +2919,20 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2812
  $item['product_id'] = $product_id;
2813
  $item['data'] = $product;
2814
  $item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2815
  global $woocommerce;
2816
  $this->analyse($woocommerce, 1);
2817
  $this->matched_sets = array();
@@ -2866,7 +2987,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2866
  }
2867
  }
2868
  }
2869
-
2870
  $amount = 0;
2871
  $discount = 0;
2872
  if ($type == 'first') {
1106
 
1107
  case 'all_products':
1108
  default:
1109
+ $is_not_in_exclude_sale_items = !$this->isItemInSaleItems($rule['exclude_sale_items'], $item['data']);
1110
+ if (!$this->isItemInProductList($rule['product_to_exclude'], $item) && $is_not_in_exclude_sale_items) {
1111
+ if(isset($rule['is_cumulative_for_products']) && $rule['is_cumulative_for_products']){
1112
+ $totalQuantityFromAllProducts = $this->getProductQuantityForCumulativeProducts($item, $product_page, $rule);
1113
+ $quantity = $totalQuantityFromAllProducts;
1114
+ }
1115
+ $discount_amount = $this->getAdjustmentAmount($item, $quantity, $this->array_first($rule['discount']), $product_page, $bogo);
1116
+ $applied_rules[$i] = $this->formatRulesToApply($discount_amount, $rule['name'], $index, $item['product_id'], $id);
1117
  }
 
 
 
1118
 
1119
+ break;
1120
  }
1121
  if(isset($applied_rules[$i]['amount']['product_ids'])){
1122
  if(!empty($applied_rules[$i]['amount']['product_ids'])){
1402
  $discount_quantity = isset($range->discount_bogo_qty)? $range->discount_bogo_qty: 1000;
1403
  $productCheapest = $this->getCheapestProductFromCart(array($productId), 0, $discount_quantity, $range);
1404
  if(!empty($productCheapest)){
1405
+ $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']), 'product_cart_item_keys' => array($productCheapest['product_cart_item_key']), 'product_discount_details' => $productCheapest['discount_details']) ;
1406
  }
1407
  } else if($discount_product_option == 'any_cheapest_from_all'){
1408
  $productCheapest = $this->getCheapestProductFromCart($productIds, 1, 1, $range);
1409
  if(!empty($productCheapest)){
1410
+ $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']), 'product_cart_item_keys' => array($productCheapest['product_cart_item_key']) ) ;
1411
  }
1412
  } else if($discount_product_option == 'any_cheapest'){
1413
  $productCheapest = $this->getCheapestProductFromCart($productIds,0, 1, $range);
1414
  if(!empty($productCheapest)){
1415
+ $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']), 'product_cart_item_keys' => array($productCheapest['product_cart_item_key']) ) ;
1416
  }
1417
  } 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'){
1418
  $discount_product_items = (isset($range->discount_product_items) ? $range->discount_product_items : 1);
1496
  }
1497
  $adjustment['price_discount'] = $productCheapest['percent'];
1498
  $adjustment['product_ids'][] = $productCheapest['product'];
1499
+ $adjustment['product_cart_item_keys'][] = $productCheapest['product_cart_item_key'];
1500
  $adjustmentValues[$productCheapest['product']] = $productCheapest['percent'];
1501
  $adjustment['product_discount_adjustment'] = $adjustmentValues;
1502
  $adjustment['product_discount_details'][$productCheapest['product']] = $productCheapest['discount_details'];
1581
  if($cheapestProductValue == 0){
1582
  $cheapestProductValue = FlycartWoocommerceProduct::get_price($_product);
1583
  $cheapestProduct = FlycartWoocommerceProduct::get_id($_product);
1584
+ $cheapestProductCartItemKey = $cart_item_key;
1585
  $quantity = $values['quantity'];
1586
  } else if($cheapestProductValue > FlycartWoocommerceProduct::get_price($_product)){
1587
  $cheapestProductValue = FlycartWoocommerceProduct::get_price($_product);
1588
  $cheapestProduct = FlycartWoocommerceProduct::get_id($_product);
1589
+ $cheapestProductCartItemKey = $cart_item_key;
1590
  $quantity = $values['quantity'];
1591
  }
1592
  }
1608
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$quantity));
1609
  else
1610
  $discount_price = $cheapestProductValue - (($cheapestProductValue/($quantity)) * ($quantity-$discount_quantity));
1611
+ return array('product' => $cheapestProduct, 'product_cart_item_key' => $cheapestProductCartItemKey, 'percent' => $discount_price, 'discount_details' => $product_discount_details, 'applied_quantity' => $quantity);
1612
  }
1613
  return array();
1614
  }
2037
  }
2038
  } elseif ($rule->apply_to == 'specific_attribute') {
2039
  $status = false;
2040
+ if(!empty($rule->attribute_to_apply)){
2041
+ $status = $this->checkProductMatchedForSpecificAttributes($rule->attribute_to_apply, $product);
2042
+ }
2043
+
2044
+ //false;
2045
  } else if ($rule->apply_to == 'all_products') {
2046
  $productToExclude = $this->getExcludeProductsFromRule($rule);
2047
  $status = false;
2107
  return $discount_range;
2108
  }
2109
 
2110
+ protected function checkProductMatchedForSpecificAttributes($attribute_to_apply, $product){
2111
+ $status = 0;
2112
+ $attribute_to_apply = json_decode($attribute_to_apply);
2113
+ $attribute_to_apply = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($attribute_to_apply);
2114
+ if(!empty($attribute_to_apply)){
2115
+ $product_id = FlycartWoocommerceProduct::get_id($product);
2116
+ $item['product_id'] = $product_id;
2117
+ $item['data'] = $product;
2118
+ $status = $this->isItemInAttributeList($attribute_to_apply, $item);
2119
+ if($status){
2120
+ return true;
2121
+ }
2122
+ if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
2123
+ $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
2124
+ $childProducts = array();
2125
+ foreach ( $children as $child ) {
2126
+ if ( '' !== FlycartWoocommerceProduct::get_price($child) ) {
2127
+ $childProducts[] = FlycartWoocommerceProduct::get_id($child);
2128
+ }
2129
+ }
2130
+ if(!empty($childProducts)){
2131
+ foreach ($childProducts as $childProductId){
2132
+ $product = FlycartWoocommerceProduct::wc_get_product($childProductId);
2133
+ $item['product_id'] = $childProductId;
2134
+ $item['data'] = $product;
2135
+ // To display the strike out price in product page for variant (specific attribute rule)
2136
+ if($product->get_type() == 'variation'){
2137
+ $p_data = $product->get_data();
2138
+ if(!empty($p_data['attributes'])){
2139
+ $attr = array();
2140
+ foreach ($p_data['attributes'] as $key => $value){
2141
+ $attr['attribute_'.$key] = $value;
2142
+ }
2143
+ $item['variation'] = $attr;
2144
+ $item['variation_id'] = $product_id;
2145
+ }
2146
+ }
2147
+ $status = $this->isItemInAttributeList($attribute_to_apply, $item);
2148
+ if($status){
2149
+ return true;
2150
+ }
2151
+ }
2152
+ }
2153
+ }
2154
+ }
2155
+
2156
+ return $status;
2157
+ }
2158
+
2159
  /**
2160
  * To get purchased product from rule
2161
  * */
2215
  break;
2216
  case 'more':
2217
  default:
2218
+ $quantity_text = ' '.$product_quantity_from.esc_html__(' or more Quantity', 'woo-discount-rules');
2219
  }
2220
 
2221
  switch ($product_buy_type) {
2281
  $table_data_content = $this->getDiscountTableContentInHTML($table_data, $data);
2282
  include($path);
2283
  //$html = ob_get_contents();
2284
+ // ob_clean();
2285
  //ob_get_clean();
2286
  }
2287
 
2433
  $price = FlycartWoocommerceProduct::get_price($product);
2434
 
2435
  //To reset the adjustment set if the Product discount adjustment exists
2436
+ $adjustment_set = $this->resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_set, $product_id, $cart_item_key);
2437
  $additionalDetails = array();
2438
 
2439
  if ($type == 'first') {
2472
  /**
2473
  * To reset the adjustment set if the Product discount adjustment exists
2474
  * */
2475
+ protected function resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_sets, $product_id, $cart_item_key){
2476
  foreach ($adjustment_sets as $key => $adjustment_set){
2477
  if(isset($adjustment_set['amount']['product_discount_adjustment']) && !empty($adjustment_set['amount']['product_discount_adjustment'])){
2478
  if(isset($adjustment_set['amount']['product_discount_adjustment'][$product_id])){
2479
+ if(isset($adjustment_set['amount']['product_cart_item_keys'])){
2480
+ if(!in_array($cart_item_key, $adjustment_set['amount']['product_cart_item_keys'])){
2481
+ unset($adjustment_sets[$key]);
2482
+ continue;
2483
+ }
2484
+ }
2485
  $adjustment_sets[$key]['amount']['price_discount'] = $adjustment_set['amount']['product_discount_adjustment'][$product_id];
2486
  $adjustment_sets[$key]['amount']['product_ids'] = array($product_id);
2487
  }
2492
  }
2493
  }
2494
  }
2495
+
2496
  return $adjustment_sets;
2497
  }
2498
 
2645
  $quantity = $cart_item['quantity'];
2646
  foreach ($additional_details as $detail){
2647
  if(isset($detail['discount_quantity']))
2648
+ if($detail['discount_quantity'] >= $quantity){
2649
+ $run_multiple_strikeout = false;
2650
+ }
2651
  }
2652
  return $run_multiple_strikeout;
2653
  }
2752
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
2753
  $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins>';
2754
  }
 
2755
  }
2756
 
2757
  $data['price_html'] = $item_price;
2776
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
2777
  $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
2778
  }
2779
+ } else if(FlycartWoocommerceProduct::get_price($product) == FlycartWoocommerceProduct::get_regular_price($product)){
2780
+ $price_to_display = FlycartWoocommerceProduct::wc_price(FlycartWoocommerceProduct::get_price($product));
2781
+ $item_price = '<span class="cart_price"><ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
2782
+ } else if(FlycartWoocommerceVersion::wcVersion('3.0')){
2783
+ $show_original = 0;
2784
+ $price_to_display = $this->checkForHighestVariantIfExists($product, $item_price, $show_original);
2785
+ if($show_original){
2786
+ if(FlycartWoocommerceProduct::get_price($product) >= FlycartWoocommerceProduct::get_regular_price($product)){
2787
+ $price_to_display = FlycartWoocommerceProduct::wc_price(FlycartWoocommerceProduct::get_price($product));
2788
+ $item_price = '<span class="cart_price"><ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
2789
+ }
2790
+
2791
+ }
2792
  }
2793
  }
2794
 
2859
  }
2860
  }
2861
  }
2862
+
2863
  return $price_to_display;
2864
  }
2865
 
2866
  /**
2867
  * Display Product sale tag on the product page
2868
  * */
2869
+ public function displayProductIsOnSaleTagOld($on_sale, $product){
2870
  $notAdmin = FlycartWooDiscountRulesGeneralHelper::doIHaveToRun();
2871
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'dont';
2872
  if($show_price_discount_on_product_page == 'show' && $notAdmin){
2874
  if($discountPrice > 0){
2875
  $on_sale = true;
2876
  }
2877
+ if(!$on_sale){
2878
+ if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
2879
+ $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
2880
+ foreach ( $children as $child ) {
2881
+ if ( '' !== FlycartWoocommerceProduct::get_price($child) ) {
2882
+ $discountPrice = $this->getDiscountPriceForTheProduct($child);
2883
+ if($discountPrice > 0){
2884
+ $on_sale = true;
2885
+ break;
2886
+ }
2887
+ }
2888
+ }
2889
+ }
2890
+ }
2891
+ }
2892
+ return $on_sale;
2893
+ }
2894
+
2895
+ /**
2896
+ * Display Product sale tag on the product page
2897
+ * */
2898
+ public function displayProductIsOnSaleTag($on_sale, $product){
2899
+ $notAdmin = FlycartWooDiscountRulesGeneralHelper::doIHaveToRun();
2900
+ $show_price_discount_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'dont';
2901
+ if($show_price_discount_on_product_page == 'show' && $notAdmin){
2902
+ global $product;
2903
+ $rules = $this->generateDiscountTableData($product);
2904
+ if(!empty($rules)){
2905
+ if(is_array($rules) && count($rules)){
2906
+ $on_sale = true;
2907
+ }
2908
+ }
2909
  }
2910
  return $on_sale;
2911
  }
2919
  $item['product_id'] = $product_id;
2920
  $item['data'] = $product;
2921
  $item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
2922
+
2923
+ // To display the strike out price in product page for variant (specific attribute rule)
2924
+ if($product->get_type() == 'variation'){
2925
+ $p_data = $product->get_data();
2926
+ if(!empty($p_data['attributes'])){
2927
+ $attr = array();
2928
+ foreach ($p_data['attributes'] as $key => $value){
2929
+ $attr['attribute_'.$key] = $value;
2930
+ }
2931
+ $item['variation'] = $attr;
2932
+ $item['variation_id'] = $product_id;
2933
+ }
2934
+ }
2935
+
2936
  global $woocommerce;
2937
  $this->analyse($woocommerce, 1);
2938
  $this->matched_sets = array();
2987
  }
2988
  }
2989
  }
2990
+
2991
  $amount = 0;
2992
  $discount = 0;
2993
  if ($type == 'first') {
readme.txt CHANGED
@@ -4,14 +4,14 @@ Donate link: https://flycart.org/
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
- Stable tag: 1.6.3
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, dynamic pricing and discounts for your WooCommerce online store.
12
  == Description ==
13
 
14
- WooCommerce discount rules helps you to create any type of bulk discounts, dynamic pricing, advanced discounts, percentage discounts for your products. Offer Product quantity based discounts, cart based discounts at a percentage or fixed amount or Buy One and Get one free (BOGO) deals or discount based on total order. Increase your sales multifold by offering dynamic pricing and discounts based on categories, products, user roles, cart items, purchase history and much more.
15
 
16
  You can set discounts for product and also for each product variation or attributes. You can also create customer specific, user roles based discounts.
17
 
@@ -193,6 +193,11 @@ Conditions can be based products, categories, customers, customer roles, shippin
193
  * Line item quantity
194
  * Total cart quantity
195
 
 
 
 
 
 
196
 
197
  = Website =
198
 
@@ -202,6 +207,10 @@ Conditions can be based products, categories, customers, customer roles, shippin
202
 
203
  [http://docs.flycart.org/woocommerce-discount-rules](http://docs.flycart.org/woocommerce-discount-rules)
204
 
 
 
 
 
205
  == Installation ==
206
  Just use the WordPress installer or upload to the /wp-content/plugins folder. Then Activate the WooCommerce Email Builder and Customizer plugin.
207
  More information could be found in the documentation
@@ -299,6 +308,12 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
299
 
300
  == Changelog ==
301
 
 
 
 
 
 
 
302
  = 1.6.3 - 05/06/18 =
303
  * Feature - BOGO for same product option(Pro)
304
  * Improvement - Support attribute for normal products(Pro)
4
  Tags: woocommerce, discounts, dynamic pricing, Buy One Get One Free, pricing deals, price rules, bulk discounts, advanced discounts, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
+ Stable tag: 1.6.4
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, dynamic pricing and discounts for your WooCommerce online store.
12
  == Description ==
13
 
14
+ WooCommerce discount rules helps you to create any type of bulk discounts, dynamic pricing, advanced discounts, percentage discounts, user role based discounts for your products. Offer Product quantity based discounts, cart based discounts at a percentage or fixed amount or Buy One and Get one free (BOGO) deals or discount based on total order. Increase your sales multifold by offering dynamic pricing and discounts based on categories, products, user roles, cart items, purchase history and much more.
15
 
16
  You can set discounts for product and also for each product variation or attributes. You can also create customer specific, user roles based discounts.
17
 
193
  * Line item quantity
194
  * Total cart quantity
195
 
196
+ = Need assistance with the discount set up? Reach out to us =
197
+
198
+ Though we have made the rule creation so simple with just 3 steps, you might still be having a few doubts. Or simply you might want to re-check if your setup is correct or you might be having a unique discount promo to run in your website. Don't worry.
199
+ Feel free to reach out to us via the Live Chat in our website or via the [support request form](https://www.flycart.org/support).
200
+ We are happy to help you and guide you with the set up.
201
 
202
  = Website =
203
 
207
 
208
  [http://docs.flycart.org/woocommerce-discount-rules](http://docs.flycart.org/woocommerce-discount-rules)
209
 
210
+ = Got questions? =
211
+
212
+ Just reach out to us and we will get back to you. You can either contact us via the Live Chat or via the [support request form](https://www.flycart.org/support)
213
+
214
  == Installation ==
215
  Just use the WordPress installer or upload to the /wp-content/plugins folder. Then Activate the WooCommerce Email Builder and Customizer plugin.
216
  More information could be found in the documentation
308
 
309
  == Changelog ==
310
 
311
+ = 1.6.4 - 12/06/18 =
312
+ * Improvement - Display table any one of variant attribute/products rule matches
313
+ * Improvement - Display sale tag, if any rule available for that product
314
+ * Fix - Applying discount for duplicate item(same product id and different attributes)
315
+ * Fix - Fatal error while saving rules
316
+
317
  = 1.6.3 - 05/06/18 =
318
  * Feature - BOGO for same product option(Pro)
319
  * Improvement - Support attribute for normal products(Pro)
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.6.3
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.6.4
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/