Discount Rules for WooCommerce - Version 1.4.38

Version Description

  • 09/01/18 =
  • Feature - Option to show sale tag in product page
Download this release

Release Info

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

Code changes from version 1.4.37 to 1.4.38

includes/pricing-rules.php CHANGED
@@ -1737,38 +1737,17 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1737
  public function replaceVisiblePricesForVariant($data, $product, $variations)
1738
  {
1739
  if(FlycartWoocommerceVersion::wcVersion('3.0')) return $data;
1740
-
1741
  $item_price = $data['price_html'];
1742
- $config = new FlycartWooDiscountBase();
1743
- $config = $config->getBaseConfig();
1744
- if (is_string($config)) $config = json_decode($config, true);
1745
- if(isset($config['price_setup'])){
1746
- $type = $config['price_setup'];
1747
- } else {
1748
- $type = 'all';
1749
- }
1750
  $notAdmin = !is_admin();
1751
- if(isset($config['show_price_discount_on_product_page'])){
1752
- $show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
1753
- } else {
1754
- $show_price_discount_on_product_page = 'dont';
1755
- }
1756
  if($show_price_discount_on_product_page == 'show' && $notAdmin){
1757
- $product_id = FlycartWoocommerceProduct::get_id($product);
1758
- $item['product_id'] = $product_id;
1759
- $item['data'] = $product;
1760
- $item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
1761
- global $woocommerce;
1762
- $this->analyse($woocommerce);
1763
- $this->matchRules($product_id, $item, 1);
1764
-
1765
- if(isset($this->matched_sets[$product_id])){
1766
- $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type, FlycartWoocommerceProduct::get_price($variations));
1767
- if($discountPrice > 0){
1768
- $price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
1769
- $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins>';
1770
- }
1771
  }
 
1772
  }
1773
 
1774
  $data['price_html'] = $item_price;
@@ -1780,42 +1759,57 @@ if (!class_exists('FlycartWooDiscountRulesPricingRules')) {
1780
  * */
1781
  public function replaceVisiblePrices($item_price, $product)
1782
  {
1783
- // Get settings
1784
- $config = new FlycartWooDiscountBase();
1785
- $config = $config->getBaseConfig();
1786
- if (is_string($config)) $config = json_decode($config, true);
1787
- if(isset($config['price_setup'])){
1788
- $type = $config['price_setup'];
1789
- } else {
1790
- $type = 'all';
1791
- }
1792
  $notAdmin = !is_admin();
1793
- if(isset($config['show_price_discount_on_product_page'])){
1794
- $show_price_discount_on_product_page = $config['show_price_discount_on_product_page'];
1795
- } else {
1796
- $show_price_discount_on_product_page = 'dont';
1797
- }
1798
  if($show_price_discount_on_product_page == 'show' && $notAdmin){
1799
- $product_id = FlycartWoocommerceProduct::get_id($product);
1800
- $item['product_id'] = $product_id;
1801
- $item['data'] = $product;
1802
- $item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
1803
- global $woocommerce;
1804
- $this->analyse($woocommerce);
1805
- $this->matchRules($product_id, $item, 1);
1806
-
1807
- if(isset($this->matched_sets[$product_id])){
1808
- $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $type);
1809
- if($discountPrice > 0){
1810
- $price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
1811
- $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
1812
- }
1813
  }
1814
  }
1815
 
1816
  return $item_price;
1817
  }
1818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1819
  /**
1820
  * Get Quantity of product in cart
1821
  * */
1737
  public function replaceVisiblePricesForVariant($data, $product, $variations)
1738
  {
1739
  if(FlycartWoocommerceVersion::wcVersion('3.0')) return $data;
 
1740
  $item_price = $data['price_html'];
 
 
 
 
 
 
 
 
1741
  $notAdmin = !is_admin();
1742
+ $show_price_discount_on_product_page = (isset($this->baseConfig['show_price_discount_on_product_page']))? $this->baseConfig['show_price_discount_on_product_page']: 'dont';
 
 
 
 
1743
  if($show_price_discount_on_product_page == 'show' && $notAdmin){
1744
+ $discountPrice = $this->getDiscountPriceForTheProduct($product, FlycartWoocommerceProduct::get_price($variations));
1745
+ if($discountPrice > 0){
1746
+ $price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
1747
+ $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
1748
+ $item_price = '<del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins>';
 
 
 
 
 
 
 
 
 
1749
  }
1750
+
1751
  }
1752
 
1753
  $data['price_html'] = $item_price;
1759
  * */
1760
  public function replaceVisiblePrices($item_price, $product)
1761
  {
 
 
 
 
 
 
 
 
 
1762
  $notAdmin = !is_admin();
1763
+ $show_price_discount_on_product_page = (isset($this->baseConfig['show_price_discount_on_product_page']))? $this->baseConfig['show_price_discount_on_product_page']: 'dont';
 
 
 
 
1764
  if($show_price_discount_on_product_page == 'show' && $notAdmin){
1765
+ $discountPrice = $this->getDiscountPriceForTheProduct($product);
1766
+ if($discountPrice > 0){
1767
+ $price_to_display = FlycartWoocommerceProduct::wc_price($discountPrice);
1768
+ $item_price = preg_replace('/<del>.*<\/del>/', '', $item_price);
1769
+ $item_price = '<span class="cart_price"><del>' . $item_price . '</del> <ins>' . ($price_to_display).$product->get_price_suffix() . '</ins></span>';
 
 
 
 
 
 
 
 
 
1770
  }
1771
  }
1772
 
1773
  return $item_price;
1774
  }
1775
 
1776
+ /**
1777
+ * Display Product sale tag on the product page
1778
+ * */
1779
+ public function displayProductIsOnSaleTag($on_sale, $product){
1780
+ $notAdmin = !is_admin();
1781
+ $show_price_discount_on_product_page = (isset($this->baseConfig['show_sale_tag_on_product_page']))? $this->baseConfig['show_sale_tag_on_product_page']: 'dont';
1782
+ if($show_price_discount_on_product_page == 'show' && $notAdmin){
1783
+ $discountPrice = $this->getDiscountPriceForTheProduct($product);
1784
+ if($discountPrice > 0){
1785
+ $on_sale = true;
1786
+ }
1787
+ }
1788
+ return $on_sale;
1789
+ }
1790
+
1791
+ /**
1792
+ * To check discount for this product or not
1793
+ * */
1794
+ public function getDiscountPriceForTheProduct($product, $variationPrice = 0){
1795
+ $discountPrice = 0;
1796
+ $product_id = FlycartWoocommerceProduct::get_id($product);
1797
+ $item['product_id'] = $product_id;
1798
+ $item['data'] = $product;
1799
+ $item['quantity'] = ($this->getQuantityOfProductInCart($product_id))+1;
1800
+ global $woocommerce;
1801
+ $this->analyse($woocommerce);
1802
+ $this->matchRules($product_id, $item, 1);
1803
+ if(isset($this->matched_sets[$product_id])){
1804
+ if($variationPrice){
1805
+ $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $this->apply_to, $variationPrice);
1806
+ } else {
1807
+ $discountPrice = $this->getAdjustmentDiscountedPrice($product, $product_id, $this->apply_to);
1808
+ }
1809
+ }
1810
+ return $discountPrice;
1811
+ }
1812
+
1813
  /**
1814
  * Get Quantity of product in cart
1815
  * */
loader.php CHANGED
@@ -152,6 +152,9 @@ if(!class_exists('FlycartWooDiscountRules')){
152
  add_action('woocommerce_thankyou', array($this->discountBase, 'storeLog'));
153
 
154
  add_action( 'woocommerce_after_checkout_form', array($this->discountBase, 'addScriptInCheckoutPage'));
 
 
 
155
  }
156
  }
157
  }
152
  add_action('woocommerce_thankyou', array($this->discountBase, 'storeLog'));
153
 
154
  add_action( 'woocommerce_after_checkout_form', array($this->discountBase, 'addScriptInCheckoutPage'));
155
+
156
+ //To enable on-sale tag
157
+ add_filter('woocommerce_product_is_on_sale', array($this->pricingRules, 'displayProductIsOnSaleTag'), 10, 2);
158
  }
159
  }
160
  }
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.37
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -238,6 +238,9 @@ Discount - Enter minimum & Maximum quantity -> Adjustment Type -> Product Discou
238
 
239
  == Changelog ==
240
 
 
 
 
241
  = 1.4.37 - 05/01/18 =
242
  * Fix - Not displaying Price display suffix
243
 
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.38
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
238
 
239
  == Changelog ==
240
 
241
+ = 1.4.38 - 09/01/18 =
242
+ * Feature - Option to show sale tag in product page
243
+
244
  = 1.4.37 - 05/01/18 =
245
  * Fix - Not displaying Price display suffix
246
 
view/settings.php CHANGED
@@ -105,7 +105,26 @@ if (is_string($data)) $data = json_decode($data, true);
105
  value="dont"><?php esc_html_e('Don\'t Show', 'woo-discount-rules'); ?>
106
  </option>
107
  </select>
108
- <div class="notice notice-info"><p><?php esc_html_e('It displays only if any rule matches based on single quantity', 'woo-discount-rules'); ?></p></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  </div>
110
  </div>
111
  <div class="row form-group">
105
  value="dont"><?php esc_html_e('Don\'t Show', 'woo-discount-rules'); ?>
106
  </option>
107
  </select>
108
+ <div class="notice notice-info"><p><?php esc_html_e('It displays only if any rule matches', 'woo-discount-rules'); ?></p></div>
109
+ </div>
110
+ </div>
111
+ <div class="row form-group">
112
+ <?php $data['show_sale_tag_on_product_page'] = (isset($data['show_sale_tag_on_product_page']) ? $data['show_sale_tag_on_product_page'] : 'dont'); ?>
113
+ <div class="col-md-2">
114
+ <label>
115
+ <?php esc_html_e('Show Sale tag on product page :', 'woo-discount-rules'); ?>
116
+ </label>
117
+ </div>
118
+ <div class="col-md-6">
119
+ <select class="selectpicker" name="show_sale_tag_on_product_page">
120
+ <option <?php if ($data['show_sale_tag_on_product_page'] == 'show') { ?> selected=selected <?php } ?>
121
+ value="show"><?php esc_html_e('Show', 'woo-discount-rules'); ?>
122
+ </option>
123
+ <option <?php if ($data['show_sale_tag_on_product_page'] == 'dont') { ?> selected=selected <?php } ?>
124
+ value="dont"><?php esc_html_e('Don\'t Show', 'woo-discount-rules'); ?>
125
+ </option>
126
+ </select>
127
+ <div class="notice notice-info"><p><?php esc_html_e('It displays only if any rule matches', 'woo-discount-rules'); ?></p></div>
128
  </div>
129
  </div>
130
  <div class="row form-group">
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.37
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1
5
  * Description: Simple Discount Rules for WooCommerce.
6
  * Author: Flycart Technologies LLP
7
  * Author URI: https://www.flycart.org
8
+ * Version: 1.4.38
9
  * Slug: woo-discount-rules
10
  * Text Domain: woo-discount-rules
11
  * Requires at least: 4.6.1