• Resolved Danusha Nuwan

    (@danushainfo)


    Today I updated the following plugins and theme in localhost before updating them of my live site.

    WooCommerce—> Version 3.6.2
    WOOCS – WooCommerce Currency Switcher—> Version 1.2.8.1
    Porto Theme—> Version 4.11.2 (Apr 23.2019)

    Now following error message is appeared in variable product page once changed the default currency through WOOCS currency switcher. Please let me how to fix that that error. I am afraid to update my live site without fix this error.

    “Warning: Division by zero in C:\xampp\htdocs\mrudukanga.lk\wp-content\themes\porto\woocommerce\single-product\sale-flash.php on line 25”

    Screenshots: Product page—> https://prnt.sc/nmqa3v
    Currency Settings—> https://prnt.sc/nmrmkz

    Sale-flash.php Code:

    <?php
    /**
     * Single Product 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) {
            $labels .= '<div class="onhot">'. ((isset($porto_settings['product-hot-label']) && $porto_settings['product-hot-label']) ? $porto_settings['product-hot-label'] : __('Hot', 'porto')) .'</div>';
        }
    }
    
    if ( $porto_settings['product-sale'] && $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 );
        if ($porto_settings['product-sale-percent'] && $percentage)
            $labels .= '<div class="onsale">'. $percentage .'%</div>';
        else
            $labels .= apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . ((isset($porto_settings['product-sale-label']) && $porto_settings['product-sale-label']) ? $porto_settings['product-sale-label'] : __('Sale', 'porto')) . '</span>', $post, $product );
    }
    echo '<div class="labels">';
    
    echo $labels;
    
    echo '</div>';
    ?>
    

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello
    for some reason the price of the product is zero. I’m not sure that it depends on my plugin.

    You can try to change this code:
    $div =($product->get_regular_price())?$product->get_regular_price() :1;

    $percentage = – round( ( ( $product->get_regular_price() – $product->get_sale_price() ) / $div) * 100 );

    Thread Starter Danusha Nuwan

    (@danushainfo)

    Hi,

    I tried to fix “sale-flash.php on line 25 error” with your code. But It wasn’t worked. No any error with single products. This error is come with variable products. I have properly filled Regular price and sales price proper manner under variation.

    Thank you.

    Thread Starter Danusha Nuwan

    (@danushainfo)

    Further to above:

    There is no error with shop currency if product is variable product. Once change the shop currency to another currency using currency switcher, line 25 error comes.

    Hello

    Try change this line – https://c2n.me/41wgW7q.png

    $div =(is_numeric($product->get_regular_price()) AND $product->get_regular_price())?$product->get_regular_price() :1;

    Drop me exact link to the issue

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Warning: Division by zero (sale-flash.php on line 25)’ is closed to new replies.