[NSFW] Percentage discount issue
-
Hello,
I recently installed this plugin to explore its functionality and applied a 25% discount rule across a category, the price is updating correctly, however the product discount label is incorrectly displaying “-100%”.
Is this a known issue or is something wrong with my setup?
Thanks
The page I need help with: [log in to see the link]
-
hello
How do you calculate %% ? Custom php code ?
I installed theme OceanWP and I see only “Sale” badge without numbers.
https://snipboard.io/d6ZbIC.jpgthanks, Alex
IF you have code for hook “woocommerce_sale_flash” – please, adapt our code
add_filter('woocommerce_sale_flash', 'adp_savings_on_sales_flash', 10, 3); function adp_savings_on_sales_flash($flash, $post, $product) { $percentage = ''; if ($product->get_type() == 'variable') { $processedProduct = adp_functions()->calculateProduct($product, 1); if ($processedProduct instanceof \ADP\BaseVersion\Includes\PriceDisplay\ProcessedVariableProduct && !is_null($processedProductLowestPrice = $processedProduct->getLowestPriceProduct()) && $processedProduct->areRulesApplied()) { $minVariationPrice = $processedProductLowestPrice->getCalculatedPrice(); $initialPrice = $processedProductLowestPrice->getOriginalPrice(); $percentage = round((($initialPrice - $minVariationPrice) / $initialPrice) * 100); } elseif ($product->is_on_sale()) { $available_variations = $product->get_variation_prices(); $max_percentage = 0; foreach ($available_variations['regular_price'] as $key => $regular_price) { $sale_price = $available_variations['sale_price'][$key]; if ($sale_price < $regular_price) { $percentage = round((($regular_price - $sale_price) / $regular_price) * 100); if ($percentage > $max_percentage) { $max_percentage = $percentage; } } } $percentage = $max_percentage; } } elseif ($product->get_type() == 'simple' || $product->get_type() == 'external' || $product->get_type() == 'variation') { $processedProduct = adp_functions()->calculateProduct($product, 1); if ($processedProduct instanceof \ADP\BaseVersion\Includes\PriceDisplay\ProcessedProductSimple && $processedProduct->areRulesApplied()) { $initialPrice = $processedProduct->getOriginalPrice(); $calculatedPrice = $processedProduct->getCalculatedPrice(); $percentage = round((($initialPrice - $calculatedPrice) / $initialPrice) * 100); } elseif ($product->is_on_sale()) { $percentage = round((($product->get_regular_price() - $product->get_sale_price()) / $product->get_regular_price()) * 100); } } return $percentage ? '<span class="onsale"> - ' . $percentage . '%</span>' : $flash; }
Hi @algolplus,
Thanks for looking into this.
In OceanWP the % discounts can be enabled via: Appearance > Customise > WooCommerce > General: https://snipboard.io/yKIZ6A.jpg
Thank you for proividing the code snippet, I did try to add it (via Code Snippets plugin), however it produced a fatal error:
Error Details ============= An error of type E_PARSE was caused in line 19 of the file /home/pipsseed/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(248) : eval()'d code. Error message: syntax error, unexpected '&'
- This reply was modified 1 year, 10 months ago by fizzers.
hi
Thank you very much.
I removed my code,
I setup rule https://snipboard.io/dBhwf5.jpg and
I see correct %% https://snipboard.io/oxD5j9.jpgBtw, have you copied code correctly ?I don’t see “&” in line 19 in my code.
thanks, AlexHi Alex,
I must have made a mistake, as snippet now successfully saves. However, even with your code all sale items are still showing -100% on the badge.
Hi @fizzers!
What theme do you use now?
Hello @thisisirene, the site is still on OceanWP.
Could you, @fizzers, please clarify whether you have enabled the option “Pricing rules>Settings>Product Price>Show On Sale badge for Simple product if price was modified” and “Calculate “On Sale” badge for variable products”?
Hi @thisisirene,
I can see the first option and it is already enabled, however I cannot see the second option in “product price” settings.
hi
2nd option is part of pro version .
But if you look at my screenshot https://snipboard.io/oxD5j9.jpg
You will see correct %% for simple products.Can it be a conflict with another plugin ?
if you have staging website – could you deactivate all other plugins (except WooCommerce and our plugin) and check results ?Hi,
In your demo site example, does the % discount still show correctly if you create a variable product and apply a discount rule?
- This reply was modified 1 year, 9 months ago by fizzers.
Yes, if I turn on “Calculate “On Sale” badge for variable products”
My results https://snipboard.io/IMZuBO.jpg for OceanWPSo you don’t need any extra code and I think it’s a conflict with another plugin.
You can sumit system report as new ticket to https://algolplus.freshdesk.com/
Visit >WooCommerce>Pricing Rules>Tools to get it.thanks, Alex
Hello,
Are you suggesting that I need the pro version of Advanced Dynamic Pricing for WooCommerce? Otherwise, I seemingly cannot enabled that option.
My question was whether the % would show correctly in your demo environment, but it appears you have the pro version enabled in there. So please could you test again with the demo with free version, and see if it works?
- This reply was modified 1 year, 9 months ago by fizzers.
For variable products – yes, you need pro version.
But you don’t see %% for simple products- it means there’s a different problem.
Our products are all variable products, but when I create a simple product the discount does display correctly. Unfortunately, I was unaware that the pro version was a requirement. I will search for another solution.
- The topic ‘[NSFW] Percentage discount issue’ is closed to new replies.