Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

Discount percentage instead of "On sale"

Home / Forums / Virtue Theme / Discount percentage instead of "On sale"

This topic is: Resolved
[Resolved]
Posted in: Virtue Theme

Tagged: 

June 3, 2016 at 11:54 am

Hello ,

I want to have a discount percentage instead of “On sale” on the products that are on sale.
I found a function that you have posted on WordPress forums and i have added it on my functions.php of my child theme :

add_filter( ‘woocommerce_sale_flash’, ‘kt_custom_sales_flash’, 10, 2 );
function kt_custom_sales_flash() {
global $product;
$percentage = round( ( ( $product->regular_price – $product->sale_price ) / $product->regular_price ) * 100 );
return ‘<span class=”onsale bg_primary headerfont”>’. sprintf( __(‘ Save %s’, ‘virtue’ ), $percentage . ‘%’ ).'</span>’;
}

but that returns this on my site : Warning: Division by zero in /functions.php on line 14.

What am i doing wrong?

Thanks in advance for your cooperation

  • The topic ‘Discount percentage instead of "On sale"’ is closed to new replies.