I need to modify WooCommerce price html on single product entry summary. My goal is to show "You save X%, Listprice and Your price labels in prices". I managed to do this:
add_filter('woocommerce_get_price_html', 'custom_entry_summary_price_format', 10, 2);
function custom_entry_summary_price_format($price, $product)
{
// Only for logged-in users
if (!is_user_logged_in()) return $price;
// Only on single product entry summary
global $wp_current_filter;
if (!(is_product() && in_array('woocommerce_single_product_summary', $wp_current_filter ?? []))) {
return $price;
}
// If not on sale, return regular price with label
if (!$product->is_on_sale()) {
return '<span class="price-label">Listprice:</span> ' . $price;
}
// On sale: show discount, regular price and sale price with labels
$regular_price = wc_price($product->get_regular_price());
$sale_price = wc_price($product->get_sale_price());
$discount = round((($product->get_regular_price() - $product->get_sale_price()) / $product->get_regular_price()) * 100);
return '<span class="sale-percentage">You save ' . $discount . '%</span>
<span class="price-regular"><span class="price-label">List price:</span> <del>' . $regular_price . '</del></span>
<span class="price-sale"><span class="price-label">Your price:</span> ' . $sale_price . '</span>';
}
However if i have set up for example dynamic pricing rule for sepcific customer this formatting is overriden. How to preserve this kind of format for pricing?
Hi,
I need to modify WooCommerce price html on single product entry summary. My goal is to show "You save X%, Listprice and Your price labels in prices". I managed to do this:
However if i have set up for example dynamic pricing rule for sepcific customer this formatting is overriden. How to preserve this kind of format for pricing?