<?php | |
// Add save percent next to sale item prices. | |
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 ); | |
function woocommerce_custom_sales_price( $price, $product ) { | |
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 ); | |
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' ); | |
} | |
?> |
This comment has been minimized.
This comment has been minimized.
@rsangeethk No, you simply add the code to your theme's functions.php file and it will automatically add the Save x% next to prices of products that are on sale. |
This comment has been minimized.
This comment has been minimized.
@kloon. Thanks a lot. |
This comment has been minimized.
This comment has been minimized.
Above works fantastically. Thanks for that. Can you also convert the above code for I have following code but it gives [Warning; Divide by zero] only when the products are listed in the side bar. You can see it here http://www.silkaurora.com.au/ // Add save percent next to variable sale item prices. This is causing 'devide by zero' warning on the left hand widget area |
This comment has been minimized.
This comment has been minimized.
@ShimonGrout For the css styling, I propose this : // Add save percent next to sale item prices. Save %s', 'woocommerce' ), $percentage . '% ' );} |
This comment has been minimized.
This comment has been minimized.
@kloon i have just copy and paste the above code mention for functions.php at the bottom of my functions.php but its getting error.. Please help me how can i make the percentage on the product of sale price. Thank in advance !! |
This comment has been minimized.
This comment has been minimized.
This snippet doesnt work on the latest version.. |
This comment has been minimized.
This comment has been minimized.
@kloon works perfectly thanks, i'm also trying to add a css class to manage which prices display the saving. |
This comment has been minimized.
This comment has been minimized.
@kloon , how can I output the total savings in the cart page. How to modify the foreach loop to calculate total savings of all products the cart and show it in the cart page, what filter/hook to use ? This code works perfectly for single product page. Can you please help me modifying the function to show total savings of all the products in the cart, in the cart page. Thanks. |
This comment has been minimized.
This comment has been minimized.
@oavs Did you manage this to work on variable products? |
This comment has been minimized.
This comment has been minimized.
edit and delete that code from server file manager |
This comment has been minimized.
This comment has been minimized.
This isn't working with the latest WooCommerce update.. please can you update page? thank for you! |
This comment has been minimized.
This comment has been minimized.
not working on a variable products |
This comment has been minimized.
This comment has been minimized.
Any update for woocommerce 3? thank you! |
This comment has been minimized.
This comment has been minimized.
Try this: function woocommerce_saved_sales_price( $price, $product ) { |
This comment has been minimized.
This comment has been minimized.
For those who want a percentage just try this function woocommerce_saved_sales_price( $price, $product ) { |
This comment has been minimized.
This comment has been minimized.
Hi giroin, I have used following your code to show total percentage discount on Product page and categories page: function woocommerce_saved_sales_price( $price, $product ) { It's work good. But This code also show Total percentage off on without Sale Products . See this screen shot -> http://nimb.ws/y4xk5X So please provide me solutions for how to hide this on without sale price. I am waiting for your replay. Thanks, |
This comment has been minimized.
This comment has been minimized.
Does anyone know of a code that works with variations ? |
This comment has been minimized.
This comment has been minimized.
try this: `function woocommerce_saved_sales_price( $price, $product ) { add_filter( 'woocommerce_get_price_html', 'woocommerce_saved_sales_price', 10, 2 );` |
This comment has been minimized.
This comment has been minimized.
Its not working on variable products.Please help me out. |
This comment has been minimized.
This comment has been minimized.
the code above does not work with WC 3.1.2.... |
This comment has been minimized.
This comment has been minimized.
found a solution here- answered May 3 at 22:46
|
This comment has been minimized.
thanks alot it helped me,do i need to add any code in theme to call the save :percentage