Using Woocommerce, I have successively removed sale badges and prices from product archives pages with the following code:
// Remove Sales Flash
add_filter('woocommerce_sale_flash', 'woo_custom_hide_sales_flash');
function woo_custom_hide_sales_flash()
{
return false;
}
// Remove prices on archives pages
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
All the products are variable products and all variations have the same prices. Also actually all prices are sale prices.
I would like to add the discounted percentage after each variable price range, in single product pages. I have tried using the following code:
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 . '%' );
}
But I dont get anything
What I am doing wrong and how can this be done?
Any help on this will be appreciated.