Discount Rules for WooCommerce - Version 1.6.3

Version Description

  • 05/06/18 =
  • Feature - BOGO for same product option(Pro)
  • Improvement - Support attribute for normal products(Pro)
  • Fix - Undefined index data
  • Fix: Cheapest of all not works when rule doesn't matches for second item (while having apply first rule in settings)
Download this release

Release Info

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

Code changes from version 1.6.2 to 1.6.3

assets/js/app.js CHANGED
@@ -159,7 +159,7 @@ function trigger_woocommerce_tooltip(){
159
  '<option value="percentage_discount"> Percentage Discount </option> <option value="price_discount">Price Discount </option> <option value="product_discount">Product Discount </option> </select></label> <label><span class="hide-for-product-discount">Value</span>' +
160
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
161
  form += '<div class="price_discount_product_list_con hide">' +
162
- ' 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>' +
163
  '<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>' +
164
  '</select>';
165
  form += '<div class="discount_product_option_bogo_con">';
@@ -538,7 +538,7 @@ function trigger_woocommerce_tooltip(){
538
  var discount_product_option_bogo_con = $(this).closest('.price_discount_product_list_con').find('.discount_product_option_bogo_con');
539
  discount_category.addClass('hide');
540
  discount_product_option_bogo_con.addClass('hide');
541
- if($(this).val() == 'all'){
542
  discount_product_option_bogo_con.removeClass('hide');
543
  }
544
  if($(this).val() == 'any_cheapest_from_all' || $(this).val() == 'more_than_one_cheapest_from_all'){
@@ -555,6 +555,9 @@ function trigger_woocommerce_tooltip(){
555
  discount_product.addClass('hide');
556
  discount_category.removeClass('hide');
557
  }
 
 
 
558
 
559
  });
560
  $('select.discount_product_option').trigger('change');
159
  '<option value="percentage_discount"> Percentage Discount </option> <option value="price_discount">Price Discount </option> <option value="product_discount">Product Discount </option> </select></label> <label><span class="hide-for-product-discount">Value</span>' +
160
  '<input type="text" name="discount_range[' + count + '][to_discount]" class="form-control price_discount_amount" value="" placeholder="ex. 50"> ';
161
  form += '<div class="price_discount_product_list_con hide">' +
162
+ ' Apply for <select class="selectpicker discount_product_option" name="discount_range['+count+'][discount_product_option]"><option value="all">All selected</option><option value="same_product">Same product</option><option value="any_cheapest">Any one cheapest from selected</option><option value="any_cheapest_from_all">Any one cheapest from all products</option>' +
163
  '<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>' +
164
  '</select>';
165
  form += '<div class="discount_product_option_bogo_con">';
538
  var discount_product_option_bogo_con = $(this).closest('.price_discount_product_list_con').find('.discount_product_option_bogo_con');
539
  discount_category.addClass('hide');
540
  discount_product_option_bogo_con.addClass('hide');
541
+ if($(this).val() == 'all' || $(this).val() == 'same_product'){
542
  discount_product_option_bogo_con.removeClass('hide');
543
  }
544
  if($(this).val() == 'any_cheapest_from_all' || $(this).val() == 'more_than_one_cheapest_from_all'){
555
  discount_product.addClass('hide');
556
  discount_category.removeClass('hide');
557
  }
558
+ if($(this).val() == 'same_product'){
559
+ discount_product.addClass('hide');
560
+ }
561
 
562
  });
563
  $('select.discount_product_option').trigger('change');
includes/pricing-rules.php CHANGED
@@ -1002,6 +1002,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1002
  */
1003
  public function matchRules($index, $item, $product_page = 0, $bogo = 0)
1004
  {
 
1005
  if(!FlycartWooDiscountRulesGeneralHelper::haveToApplyTheRules()) return false;
1006
  $applied_rules = array();
1007
  $quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
@@ -1396,7 +1397,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1396
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
1397
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
1398
  $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
1399
- if($discount_product_option == 'any_cheapest_from_all'){
 
 
 
 
 
 
 
1400
  $productCheapest = $this->getCheapestProductFromCart($productIds, 1, 1, $range);
1401
  if(!empty($productCheapest)){
1402
  $adjustment = array ( 'price_discount' => $productCheapest['percent'], 'product_ids' => array($productCheapest['product']) ) ;
@@ -1697,6 +1705,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1697
  */
1698
  public function isItemInAttributeList($attribute_list, $product)
1699
  {
 
 
 
 
 
 
 
 
1700
  if (!isset($product['variation_id']) || !$product['variation_id'] ) return false;
1701
  if (!isset($product['variation']) || empty($product['variation']) ) return false;
1702
  if(empty($attribute_list)) return false;
@@ -1705,6 +1721,61 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1705
  return $status;
1706
  }
1707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1708
  /**
1709
  * Sort cart by price
1710
  *
@@ -2199,7 +2270,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2199
  if($discount_product_discount_type == "limited_percent" && $discount_product_percent>0){
2200
  $htmlProduct .= $discount_product_percent.esc_html__('% discount in ', 'woo-discount-rules');
2201
  }
2202
- if($discount_product_option == 'any_cheapest_from_all'){
 
 
2203
  $htmlProduct .= esc_html__('any cheapest one from cart', 'woo-discount-rules');
2204
  } else {
2205
  if($discount_product_option == 'any_cheapest'){
@@ -2305,6 +2378,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2305
  //To reset the adjustment set if the Product discount adjustment exists
2306
  $adjustment_set = $this->resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_set, $product_id);
2307
  $additionalDetails = array();
 
2308
  if ($type == 'first') {
2309
  // For Apply the First Rule.
2310
  $discount = $this->getAmount($adjustment_set, $price, 'first');
@@ -2385,6 +2459,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2385
  foreach ($sets as $id => $set) {
2386
  // For the First price, it will return the amount after get hit.
2387
  if ($by == 'first') {
 
 
 
2388
  if (isset($set['amount']['percentage_discount'])) {
2389
  $discount = ($price / 100) * $set['amount']['percentage_discount'];
2390
  } else if (isset($set['amount']['price_discount'])) {
@@ -2644,6 +2721,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2644
  }
2645
 
2646
  public function checkForHighestVariantIfExists($product, $price_to_display, &$show_original){
 
2647
  $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
2648
  $child_prices = array();
2649
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
@@ -2667,7 +2745,6 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2667
  $minProductId = $minProductIds[0];
2668
  }
2669
  }
2670
-
2671
  if($maxProductId){
2672
  $maxProduct = FlycartWoocommerceProduct::wc_get_product($maxProductId);
2673
  $greatestDiscountPrice = $this->getDiscountPriceForTheProduct($maxProduct);
@@ -2684,9 +2761,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2684
  } else {
2685
  $leastDiscountPrice = FlycartWoocommerceProduct::wc_price(FlycartWoocommerceProduct::get_price($minProduct));
2686
  }
2687
- $price_to_display = $leastDiscountPrice.' - '.$greatestDiscountPrice;
 
 
 
 
2688
  } else {
2689
- $price_to_display .= ' - '.$greatestDiscountPrice;
 
2690
  }
2691
  } else {
2692
  if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
1002
  */
1003
  public function matchRules($index, $item, $product_page = 0, $bogo = 0)
1004
  {
1005
+ if(!isset($item['data']) || empty($item['data'])) return false;
1006
  if(!FlycartWooDiscountRulesGeneralHelper::haveToApplyTheRules()) return false;
1007
  $applied_rules = array();
1008
  $quantity = (isset($item['quantity']) ? $item['quantity'] : 0);
1397
  $discount_product_option = isset($range->discount_product_option) ? $range->discount_product_option : 'all';
1398
  $productIds = isset($range->discount_product) ? $range->discount_product : array();
1399
  $productIds = FlycartWoocommerceVersion::backwardCompatibilityStringToArray($productIds);
1400
+ if($discount_product_option == 'same_product'){
1401
+ $productId = FlycartWoocommerceProduct::get_id($item['data']);
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']) ) ;
1705
  */
1706
  public function isItemInAttributeList($attribute_list, $product)
1707
  {
1708
+ $parent_product = FlycartWoocommerceProduct::wc_get_product($product['product_id']);
1709
+ $parent_id = FlycartWoocommerceProduct::get_parent_id($parent_product);
1710
+ if($parent_id){
1711
+ $parent_product = FlycartWoocommerceProduct::wc_get_product($parent_id);
1712
+ }
1713
+ $status = $this->hasAttributeInParentProduct($parent_product, $attribute_list);
1714
+ if($status) return true;
1715
+
1716
  if (!isset($product['variation_id']) || !$product['variation_id'] ) return false;
1717
  if (!isset($product['variation']) || empty($product['variation']) ) return false;
1718
  if(empty($attribute_list)) return false;
1721
  return $status;
1722
  }
1723
 
1724
+ /**
1725
+ * Check default attributes for products without variants
1726
+ *
1727
+ * @param object $product
1728
+ * @param array $attribute_list
1729
+ * @return boolean
1730
+ * */
1731
+ protected function hasAttributeInParentProduct($product, $attribute_list){
1732
+ $status = 0;
1733
+ if(FlycartWoocommerceVersion::wcVersion('3.0')){
1734
+ $attributes_parent = $product->get_attributes();
1735
+ } else {
1736
+ $attributes_parent = $product->product_attributes;
1737
+ }
1738
+ if(!empty($attributes_parent) && is_array($attributes_parent)){
1739
+ foreach ($attributes_parent as $attributes){
1740
+ if(FlycartWoocommerceVersion::wcVersion('3.0')){
1741
+ if(!empty($attributes) && is_object($attributes)){
1742
+ $variation = $attributes->get_variation();
1743
+ if(!(int)$variation){
1744
+ $options = $attributes->get_options();
1745
+ if(!empty($options) && is_array($options)){
1746
+ if (count(array_intersect($attribute_list, $options)) > 0){
1747
+ $status = true;
1748
+ break;
1749
+ }
1750
+ }
1751
+ }
1752
+ }
1753
+ } else {
1754
+ if(!empty($attributes)){
1755
+ $variation = $attributes['is_variation'];
1756
+ if(!(int)$variation){
1757
+ $attribute_terms = get_the_terms($product->id, $attributes['name']);
1758
+ if(!empty($attribute_terms)){
1759
+ $options = array();
1760
+ foreach ($attribute_terms as $attribute_term){
1761
+ $options[] = $attribute_term->term_id;
1762
+ }
1763
+ if(!empty($options) && is_array($options)){
1764
+ if (count(array_intersect($attribute_list, $options)) > 0){
1765
+ $status = true;
1766
+ break;
1767
+ }
1768
+ }
1769
+ }
1770
+ }
1771
+ }
1772
+ }
1773
+ }
1774
+ }
1775
+
1776
+ return $status;
1777
+ }
1778
+
1779
  /**
1780
  * Sort cart by price
1781
  *
2270
  if($discount_product_discount_type == "limited_percent" && $discount_product_percent>0){
2271
  $htmlProduct .= $discount_product_percent.esc_html__('% discount in ', 'woo-discount-rules');
2272
  }
2273
+ if($discount_product_option == 'same_product'){
2274
+ $htmlProduct .= esc_html__('same product', 'woo-discount-rules');
2275
+ } elseif($discount_product_option == 'any_cheapest_from_all'){
2276
  $htmlProduct .= esc_html__('any cheapest one from cart', 'woo-discount-rules');
2277
  } else {
2278
  if($discount_product_option == 'any_cheapest'){
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') {
2383
  // For Apply the First Rule.
2384
  $discount = $this->getAmount($adjustment_set, $price, 'first');
2459
  foreach ($sets as $id => $set) {
2460
  // For the First price, it will return the amount after get hit.
2461
  if ($by == 'first') {
2462
+ if(empty($set['amount'])){
2463
+ continue;
2464
+ }
2465
  if (isset($set['amount']['percentage_discount'])) {
2466
  $discount = ($price / 100) * $set['amount']['percentage_discount'];
2467
  } else if (isset($set['amount']['price_discount'])) {
2721
  }
2722
 
2723
  public function checkForHighestVariantIfExists($product, $price_to_display, &$show_original){
2724
+ $display_only_lowest_price = 0;
2725
  $tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
2726
  $child_prices = array();
2727
  $children = array_filter( array_map( 'wc_get_product', FlycartWoocommerceProduct::get_children($product) ), 'wc_products_array_filter_visible_grouped' );
2745
  $minProductId = $minProductIds[0];
2746
  }
2747
  }
 
2748
  if($maxProductId){
2749
  $maxProduct = FlycartWoocommerceProduct::wc_get_product($maxProductId);
2750
  $greatestDiscountPrice = $this->getDiscountPriceForTheProduct($maxProduct);
2761
  } else {
2762
  $leastDiscountPrice = FlycartWoocommerceProduct::wc_price(FlycartWoocommerceProduct::get_price($minProduct));
2763
  }
2764
+ if($display_only_lowest_price){
2765
+ $price_to_display = $leastDiscountPrice;
2766
+ } else {
2767
+ $price_to_display = $leastDiscountPrice.' - '.$greatestDiscountPrice;
2768
+ }
2769
  } else {
2770
+ if(!$display_only_lowest_price)
2771
+ $price_to_display .= ' - '.$greatestDiscountPrice;
2772
  }
2773
  } else {
2774
  if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
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, pricing deals
5
  Requires at least: 4.4.1
6
  Tested up to: 4.9
7
- Stable tag: 1.6.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -35,9 +35,11 @@ Display the pricing discount table beautifully on the product page. Start sellin
35
  * Date based discount (validity)
36
  * Show discount table on product pages
37
 
 
 
38
  = PRO features =
39
 
40
- (All features of the free version, plus)[PRO version](https://www.flycart.org/products/wordpress/woocommerce-discount-rules):
41
  * Fixed price discounts ( Get $9 discount for purchasing over 6 items)
42
  * Category specific discount conditions ( Get 25 % off on all items under Summer Collection )
43
  * Buy One Get One Free discounts in WooCommerce (BOGO Deals) [Example: Buy 2 get 1 cheapest product free](http://docs.flycart.org/woocommerce-discount-rules/buy-one-get-one-deals/buy-2-and-get-1-cheapest-free-repeat)
@@ -297,6 +299,12 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
297
 
298
  == Changelog ==
299
 
 
 
 
 
 
 
300
  = 1.6.2 - 29/05/18 =
301
  * Feature - Exclude sale item option(Pro)
302
  * Feature - Cumulative option for attributes(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.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
35
  * Date based discount (validity)
36
  * Show discount table on product pages
37
 
38
+ [PRO version](https://www.flycart.org/products/wordpress/woocommerce-discount-rules)
39
+
40
  = PRO features =
41
 
42
+ * All features of the free version, plus)
43
  * Fixed price discounts ( Get $9 discount for purchasing over 6 items)
44
  * Category specific discount conditions ( Get 25 % off on all items under Summer Collection )
45
  * Buy One Get One Free discounts in WooCommerce (BOGO Deals) [Example: Buy 2 get 1 cheapest product free](http://docs.flycart.org/woocommerce-discount-rules/buy-one-get-one-deals/buy-2-and-get-1-cheapest-free-repeat)
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)
305
+ * Fix - Undefined index data
306
+ * Fix: Cheapest of all not works when rule doesn't matches for second item (while having apply first rule in settings)
307
+
308
  = 1.6.2 - 29/05/18 =
309
  * Feature - Exclude sale item option(Pro)
310
  * Feature - Cumulative option for attributes(Pro)
view/view-pricing-rules.php CHANGED
@@ -604,6 +604,7 @@ if($isPro){
604
  <?php esc_html_e('Apply for', 'woo-discount-rules') ?>
605
  <select class="selectpicker discount_product_option" name="discount_range[<?php echo $fieldIndex; ?>][discount_product_option]">
606
  <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
 
607
  <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>
608
  <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>
609
  <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>
604
  <?php esc_html_e('Apply for', 'woo-discount-rules') ?>
605
  <select class="selectpicker discount_product_option" name="discount_range[<?php echo $fieldIndex; ?>][discount_product_option]">
606
  <option value="all"<?php echo ($discount_product_option == 'all')? ' selected="selected"': '' ?>><?php esc_html_e('All selected', 'woo-discount-rules') ?></option>
607
+ <option value="same_product"<?php echo ($discount_product_option == 'same_product')? ' selected="selected"': '' ?>><?php esc_html_e('Same product', 'woo-discount-rules') ?></option>
608
  <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>
609
  <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>
610
  <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>
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.2
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.3
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/