Discount Rules for WooCommerce - Version 1.6.11

Version Description

  • 02/08/18 =
  • Fix - Duplicate apply of BOGO rules
Download this release

Release Info

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

Code changes from version 1.6.10 to 1.6.11

Files changed (4) hide show
  1. includes/pricing-rules.php +42 -13
  2. loader.php +11 -2
  3. readme.txt +4 -1
  4. woo-discount-rules.php +1 -1
includes/pricing-rules.php CHANGED
@@ -2554,7 +2554,14 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2554
  $product = $woocommerce->cart->cart_contents[$cart_item_key]['data'];
2555
  $product_id = FlycartWoocommerceProduct::get_id($product);
2556
  $original_product = FlycartWoocommerceProduct::wc_get_product($product_id);
2557
- $price = FlycartWoocommerceProduct::get_price($original_product);
 
 
 
 
 
 
 
2558
 
2559
  //To reset the adjustment set if the Product discount adjustment exists
2560
  $adjustment_set = $this->resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_set, $product_id, $cart_item_key);
@@ -2745,7 +2752,15 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2745
  $product = $woocommerce->cart->cart_contents[$item]['data'];
2746
 
2747
  $product_id = FlycartWoocommerceProduct::get_id($product);
2748
- $original_product = FlycartWoocommerceProduct::wc_get_product($product_id);
 
 
 
 
 
 
 
 
2749
 
2750
  // Log changes
2751
  $woocommerce->cart->cart_contents[$item]['woo_discount'] = array(
@@ -2757,6 +2772,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2757
  // Actually adjust price in cart
2758
  // $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
2759
  FlycartWoocommerceProduct::set_price($product, $amount);
 
2760
  }
2761
 
2762
  protected function hasToSplitTheStrikeOutInCart($cart_item, $additional_details){
@@ -2892,10 +2908,13 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2892
  * */
2893
  public function replaceVisiblePrices($item_price, $product)
2894
  {
2895
- if (!(defined('DOING_AJAX') && DOING_AJAX)) {
2896
- $parent_id = FlycartWoocommerceProduct::get_parent_id($product);
2897
- if($parent_id){
2898
- return $item_price;
 
 
 
2899
  }
2900
  }
2901
 
@@ -2917,7 +2936,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2917
  self::$product_has_strike_out[$product_id]['has_strikeout'] = 1;
2918
  self::$product_has_strike_out[$product_id]['new_strikeout_html'] = ($price_to_display).$product->get_price_suffix();
2919
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
 
2920
  $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
 
2921
  }
2922
  }
2923
  }
@@ -2930,11 +2951,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2930
  * */
2931
  public function replaceVisiblePricesOptimized($item_price, $product)
2932
  {
 
 
2933
  $runTheRulesEvenInAjax = apply_filters('woo_discount_rules_run_strike_out_for_ajax', false, $product);
2934
- if (!(defined('DOING_AJAX') && DOING_AJAX)) {
2935
- $parent_id = FlycartWoocommerceProduct::get_parent_id($product);
2936
- if($parent_id){
2937
- return $item_price;
 
 
 
 
2938
  }
2939
  }
2940
 
@@ -2948,7 +2975,9 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2948
  if(isset(self::$product_has_strike_out[$product_id]) && self::$product_has_strike_out[$product_id]['has_strikeout']){
2949
  if(self::$product_has_strike_out[$product_id]['has_strikeout'] && !empty(self::$product_has_strike_out[$product_id]['new_strikeout_html'])){
2950
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
 
2951
  $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . (self::$product_has_strike_out[$product_id]['new_strikeout_html']) . '</ins></span>';
 
2952
  }
2953
  } else {
2954
  $item_price = $this->replaceVisiblePrices($item_price, $product);
@@ -2974,7 +3003,8 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
2974
  }
2975
  } else {
2976
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_price_discount_on_product_page']))? $this->baseConfig['show_price_discount_on_product_page']: 'dont';
2977
- if($show_price_discount_on_product_page == 'show'){
 
2978
  $this->replaceVisiblePrices('', $product);
2979
  if(isset(self::$product_on_sale[$product_id])){
2980
  if(self::$product_on_sale[$product_id]){
@@ -3086,7 +3116,7 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3086
  * Display Product sale tag on the product page
3087
  * */
3088
  public function displayProductIsOnSaleTag($on_sale, $product){
3089
- $runTheRulesEvenInAjax = apply_filters('woo_discount_rules_run_sale_tag_for_ajax', false, $product);
3090
  $notAdmin = FlycartWooDiscountRulesGeneralHelper::doIHaveToRun();
3091
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'dont';
3092
  if($show_price_discount_on_product_page == 'show' && ($notAdmin || $runTheRulesEvenInAjax)){
@@ -3103,7 +3133,6 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
3103
  }
3104
  }
3105
 
3106
-
3107
  if(!$on_sale){
3108
  if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
3109
  if(FlycartWoocommerceVersion::wcVersion('3.1.0')){
2554
  $product = $woocommerce->cart->cart_contents[$cart_item_key]['data'];
2555
  $product_id = FlycartWoocommerceProduct::get_id($product);
2556
  $original_product = FlycartWoocommerceProduct::wc_get_product($product_id);
2557
+
2558
+ //Check for wholesale price
2559
+ $hasWholesalePrice = apply_filters('woo_discount_rules_has_price_override', false, $product);
2560
+ if($hasWholesalePrice){
2561
+ $price = FlycartWoocommerceProduct::get_price($product);
2562
+ } else {
2563
+ $price = FlycartWoocommerceProduct::get_price($original_product);
2564
+ }
2565
 
2566
  //To reset the adjustment set if the Product discount adjustment exists
2567
  $adjustment_set = $this->resetTheDiscountIfProductDiscountAdjustmentExists($adjustment_set, $product_id, $cart_item_key);
2752
  $product = $woocommerce->cart->cart_contents[$item]['data'];
2753
 
2754
  $product_id = FlycartWoocommerceProduct::get_id($product);
2755
+
2756
+ //Check for price get override
2757
+ $hasWholesalePrice = apply_filters('woo_discount_rules_has_price_override', false, $product);
2758
+ if($hasWholesalePrice){
2759
+ $original_product = $product;
2760
+ } else {
2761
+ $original_product = FlycartWoocommerceProduct::wc_get_product($product_id);
2762
+ if(isset($product->woo_discount_rules_applied) && $product->woo_discount_rules_applied) return ;
2763
+ }
2764
 
2765
  // Log changes
2766
  $woocommerce->cart->cart_contents[$item]['woo_discount'] = array(
2772
  // Actually adjust price in cart
2773
  // $woocommerce->cart->cart_contents[$item]['data']->price = $amount;
2774
  FlycartWoocommerceProduct::set_price($product, $amount);
2775
+ $product->woo_discount_rules_applied = 1;
2776
  }
2777
 
2778
  protected function hasToSplitTheStrikeOutInCart($cart_item, $additional_details){
2908
  * */
2909
  public function replaceVisiblePrices($item_price, $product)
2910
  {
2911
+ $run_variation_strike_out_with_ajax = apply_filters('woo_discount_rules_run_variation_strike_out_with_ajax', true, $product);
2912
+ if($run_variation_strike_out_with_ajax) {
2913
+ if (!(defined('DOING_AJAX') && DOING_AJAX)) {
2914
+ $parent_id = FlycartWoocommerceProduct::get_parent_id($product);
2915
+ if ($parent_id) {
2916
+ return $item_price;
2917
+ }
2918
  }
2919
  }
2920
 
2936
  self::$product_has_strike_out[$product_id]['has_strikeout'] = 1;
2937
  self::$product_has_strike_out[$product_id]['new_strikeout_html'] = ($price_to_display).$product->get_price_suffix();
2938
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
2939
+ $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
2940
  $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
2941
+ $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
2942
  }
2943
  }
2944
  }
2951
  * */
2952
  public function replaceVisiblePricesOptimized($item_price, $product)
2953
  {
2954
+ if(isset($product->woo_discount_rules_do_not_run_strikeout) && $product->woo_discount_rules_do_not_run_strikeout) return $item_price;
2955
+
2956
  $runTheRulesEvenInAjax = apply_filters('woo_discount_rules_run_strike_out_for_ajax', false, $product);
2957
+
2958
+ $run_variation_strike_out_with_ajax = apply_filters('woo_discount_rules_run_variation_strike_out_with_ajax', true, $product);
2959
+ if($run_variation_strike_out_with_ajax){
2960
+ if (!(defined('DOING_AJAX') && DOING_AJAX)) {
2961
+ $parent_id = FlycartWoocommerceProduct::get_parent_id($product);
2962
+ if($parent_id){
2963
+ return $item_price;
2964
+ }
2965
  }
2966
  }
2967
 
2975
  if(isset(self::$product_has_strike_out[$product_id]) && self::$product_has_strike_out[$product_id]['has_strikeout']){
2976
  if(self::$product_has_strike_out[$product_id]['has_strikeout'] && !empty(self::$product_has_strike_out[$product_id]['new_strikeout_html'])){
2977
  $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
2978
+ $item_price = apply_filters('woo_discount_rules_price_strikeout_before_discount_price', $item_price, $product);
2979
  $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . (self::$product_has_strike_out[$product_id]['new_strikeout_html']) . '</ins></span>';
2980
+ $item_price = apply_filters('woo_discount_rules_price_strikeout_after_discount_price', $item_price, $product);
2981
  }
2982
  } else {
2983
  $item_price = $this->replaceVisiblePrices($item_price, $product);
3003
  }
3004
  } else {
3005
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_price_discount_on_product_page']))? $this->baseConfig['show_price_discount_on_product_page']: 'dont';
3006
+ $optimize_sale_and_price_strikeout = apply_filters('woo_discount_rules_do_sale_tag_through_strikeout_price', true, $product);
3007
+ if($show_price_discount_on_product_page == 'show' && $optimize_sale_and_price_strikeout){
3008
  $this->replaceVisiblePrices('', $product);
3009
  if(isset(self::$product_on_sale[$product_id])){
3010
  if(self::$product_on_sale[$product_id]){
3116
  * Display Product sale tag on the product page
3117
  * */
3118
  public function displayProductIsOnSaleTag($on_sale, $product){
3119
+ $runTheRulesEvenInAjax = apply_filters('woo_discount_rules_run_sale_tag_for_ajax', false, $product);
3120
  $notAdmin = FlycartWooDiscountRulesGeneralHelper::doIHaveToRun();
3121
  $show_price_discount_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'dont';
3122
  if($show_price_discount_on_product_page == 'show' && ($notAdmin || $runTheRulesEvenInAjax)){
3133
  }
3134
  }
3135
 
 
3136
  if(!$on_sale){
3137
  if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
3138
  if(FlycartWoocommerceVersion::wcVersion('3.1.0')){
loader.php CHANGED
@@ -122,7 +122,10 @@ if(!class_exists('FlycartWooDiscountRules')){
122
  * */
123
  public function applyDiscountRules(){
124
  $this->discountBase->handlePriceDiscount();
125
- remove_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
 
 
 
126
  }
127
 
128
  /**
@@ -253,6 +256,13 @@ if(!class_exists('FlycartWooDiscountRules')){
253
  add_action('wp_ajax_nopriv_loadWooDiscountedPriceForVariant', array($this->pricingRules, 'getWooDiscountedPriceForVariant'));
254
  add_action('wp_ajax_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
255
  add_action('wp_ajax_nopriv_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
 
 
 
 
 
 
 
256
  // Enqueued script with localized data.
257
  wp_register_script( 'woo_discount_rules_site', WOO_DISCOUNT_URI . '/assets/js/woo_discount_rules.js', array(), WOO_DISCOUNT_VERSION );
258
  wp_localize_script('woo_discount_rules_site', 'woo_discount_rules', array(
@@ -261,7 +271,6 @@ if(!class_exists('FlycartWooDiscountRules')){
261
  'ajax_url' => admin_url('admin-ajax.php')
262
  ));
263
  wp_enqueue_script( 'woo_discount_rules_site' );
264
-
265
  }
266
 
267
  /**
122
  * */
123
  public function applyDiscountRules(){
124
  $this->discountBase->handlePriceDiscount();
125
+ $removeTheEvent = apply_filters('woo_discount_rules_remove_event_woocommerce_before_calculate_totals', false);
126
+ if(!$removeTheEvent){
127
+ remove_action('woocommerce_before_calculate_totals', array($this, 'applyDiscountRules'), 1000);
128
+ }
129
  }
130
 
131
  /**
256
  add_action('wp_ajax_nopriv_loadWooDiscountedPriceForVariant', array($this->pricingRules, 'getWooDiscountedPriceForVariant'));
257
  add_action('wp_ajax_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
258
  add_action('wp_ajax_nopriv_loadWooDiscountedDiscountTable', array($this->pricingRules, 'getWooDiscountedPriceTableForVariant'));
259
+ add_action( 'wp_enqueue_scripts', array($this, 'includeScriptAndStyles') );
260
+ }
261
+
262
+ /**
263
+ * To include the styles
264
+ * */
265
+ public function includeScriptAndStyles(){
266
  // Enqueued script with localized data.
267
  wp_register_script( 'woo_discount_rules_site', WOO_DISCOUNT_URI . '/assets/js/woo_discount_rules.js', array(), WOO_DISCOUNT_VERSION );
268
  wp_localize_script('woo_discount_rules_site', 'woo_discount_rules', array(
271
  'ajax_url' => admin_url('admin-ajax.php')
272
  ));
273
  wp_enqueue_script( 'woo_discount_rules_site' );
 
274
  }
275
 
276
  /**
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.10
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -308,6 +308,9 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
308
 
309
  == Changelog ==
310
 
 
 
 
311
  = 1.6.10 - 31/07/18 =
312
  * Improvement - Events to handle variation strikeout apply_filter('woo_discount_rules_run_variation_strikeout_through_ajax', true);
313
  * Improvement - Events to handle strikeout while load through ajax apply_filters('woo_discount_rules_run_strike_out_for_ajax', false, $product); apply_filters('woo_discount_rules_run_sale_tag_for_ajax', false, $product);
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.11
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
308
 
309
  == Changelog ==
310
 
311
+ = 1.6.11 - 02/08/18 =
312
+ * Fix - Duplicate apply of BOGO rules
313
+
314
  = 1.6.10 - 31/07/18 =
315
  * Improvement - Events to handle variation strikeout apply_filter('woo_discount_rules_run_variation_strikeout_through_ajax', true);
316
  * Improvement - Events to handle strikeout while load through ajax apply_filters('woo_discount_rules_run_strike_out_for_ajax', false, $product); apply_filters('woo_discount_rules_run_sale_tag_for_ajax', false, $product);
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.10
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.11
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Domain Path: /i18n/languages/