PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

When "Is multiple allowed" set to YES, product "discount percentage box" only displays NAN%

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi, just notice if I enable multiple currencies on my site by selecting YES in WooCommerce Currency Switcher plugin advanced options"Is multiple allowed", that the discount/sales percentage calculation for each product gets broken (shows only NAN%) in case I choose any currency other than site default currency.

I use Porto theme which is supposed to be fully compatible with the WooCommerce Currency Switcher plugin according to their manual. I did contact them about it and they disabled/enabled plugins and went through my site but didn't find anything wrong with the theme. Instead they directed me to contact Woocommerce Currency Switcher Support.

Is there a fix to this problem as I am Canadian and I use a site that needs to also show Euros and US dollars in the checkout process ...

(My purchase code can be found in hidden data field)

Hello

Are you using third party discount plugins?

Please drop me  exact link  to the  issue + wp-admin access

Hi Pablo,

Added wordpress login info to hidden private data.

I am running Alidropship and Woocommerce Square but no other third party"discount" plugins. I have tried to disable Alidropship and Square and all other plugins but still problem continues...

a

Hello

This is not standard woocommerce functionality. This is the functionality of the current theme.

Unfortunately I do not know how the theme generates these labels.

Ask the author of the theme where and how they form these labels

The sale percentage is displayed by the Porto theme's sale-flash.php file, please see code below. According to my error log this file gives the following error message as well as displays NAN% in the box.

"Warning: Division by zero in /home2/gusxa8tp/public_html/wp-content/themes/porto/woocommerce/loop/sale-flash.php on line 26"

<?php
/**
* Product loop sale flash
*
* @version 1.6.4
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

global $post, $product, $porto_settings;

$labels = '';
if ( $porto_settings['product-hot'] ) {
$featured = $product->is_featured();
if ( $featured ) {
$hot_html = '<div class="onhot">' . ( ( isset( $porto_settings['product-hot-label'] ) && $porto_settings['product-hot-label'] ) ? esc_html( $porto_settings['product-hot-label'] ) : __( 'Hot', 'porto' ) ) . '</div>';
$labels .= $hot_html;
}
}
if ( $porto_settings['product-sale'] ) {
if ( $product->is_on_sale() ) {
$percentage = 0;
if ( $product->get_regular_price() ) {
$percentage = - round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
} elseif ( 'variable' == $product->get_type() && $product->get_variation_regular_price() ) {
$percentage = - round( ( ( $product->get_variation_regular_price() - $product->get_variation_sale_price() ) / $product->get_variation_regular_price() ) * 100 );
}
if ( $porto_settings['product-sale-percent'] && $percentage ) {
$sales_html = '<div class="onsale">' . $percentage . '%</div>';
} else {
$sales_html = apply_filters( 'woocommerce_sale_flash', '<div class="onsale">' . ( ( isset( $porto_settings['product-sale-label'] ) && $porto_settings['product-sale-label'] ) ? esc_html( $porto_settings['product-sale-label'] ) : esc_html__( 'Sale', 'porto' ) ) . '</div>', $post, $product );
}
$labels .= $sales_html;
}
}

if ( $labels ) {
echo '<div class="labels">' . porto_filter_output( $labels ) . '</div>';
}

$availability = $product->get_availability();
if ( 'out-of-stock' == $availability['class'] ) {
if ( $porto_settings['product-stock'] ) {
echo apply_filters( 'woocommerce_stock_html', '<div class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</div>', $availability['availability'] );
}
} else {
if ( '2' != $porto_settings['add-to-cart-notification'] ) {
echo '<div data-link="' . esc_url( get_permalink( wc_get_page_id( 'cart' ) ) ) . '" class="viewcart' . ' viewcart-' . $product->get_id() . '" title="' . esc_attr__( 'View Cart', 'porto' ) . '"></div>';
}
}

Нello

Please add  FTP access  I will check/fix  it

Hi Pablo, please find FTP info in private data for this topic

Hello

Please  do  test

 

Yes,"discount percentage" on home page and archives is working now. What change did you make for it to work?

I see still however, when opening a discounted product, a green box with NAN% is still displayed on top of main product image. If I turn it back to Canadian dollars it shows"SALE" in the green box. I don't know if this is in the same woocommerce sales flash file though

Hello

I will check it today

Hello

https://c2n.me/48Xxdr5.png - Unfortunately I can not check your site

Sorry, my Wordpress SEO plugin was out of date and made a fatal error, thats why we couldnt enter the site. Anyways, I looked at the code that you added and made the same changes to the sale-flash.php for single-product pages and now that page seems to be working too. Thank you so much Pablo for your amazing support!

I am guessing that this is your updated code?

$percentage = 0;
$reg_p=floatval($product->get_regular_price());
if ( $reg_p ) {
$percentage = - round( ( ( $reg_p - $product->get_sale_price() ) / $reg_p ) * 100 );
} elseif ( 'variable' == $product->get_type() && $product->get_variation_regular_price() ) {
$percentage = - round( ( ( $product->get_variation_regular_price() - $product->get_variation_sale_price() ) / $product->get_variation_regular_price() ) * 100 );
}

Hello

I am guessing that this is your updated code? - Yes! correct!

Welcome and thank you;)