最终解决方案:我添加了 25% 的折扣 + 自定义文本
function wptips_custom_html_addon_to_price( $price, $product ) {
$pretinitial = $price;
$sale_price = $product->sale_price;
if (!empty($sale_price)) {
$pretfinalscos = $sale_price;
}
else
{
$pretfinalscos = $pretinitial;
}
$pretfinal = preg_replace("/[^0-9,.]/", "", "$pretfinalscos");
$pretfinal = str_replace(',', '.', $pretfinal);
$pricegold = $pretfinal - ($pretfinal * (25 / 100));
$html_price_suffix = '<span style="color:black;" class="price-suffix"> <br>Cu abonamentul Gold '.number_format((float)$pricegold, 2, '.', '').' lei</span>'; // custom suffix html that you want to add after price
if ( !empty( $price ) ) {
$price = $html_price_prefix . ' ' . $price . ' ' . $html_price_suffix;
return $price;
} else {
return $price;
}
}
add_filter( 'woocommerce_get_price_html', 'wptips_custom_html_addon_to_price', 999, 2 );
add_filter( 'woocommerce_cart_item_price', 'wptips_custom_html_addon_to_price', 999, 2 );