在商店页面中显示最大可变价格 - Woocommerce

时间:2021-01-27 09:01:30

标签: woocommerce variant price

我有这个代码来显示价格。

function edit_selected_variation_price( $data, $product, $variation ) {
$price = $variation->price;
$price_incl_tax = $price + round($price * ( 23 / 100 ), 2);
$price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
$price = number_format($price, 2, ",", ".");
$display_price = '<div><span class="price">';
$display_price .= '<span>Cena netto</span><span class="amount">' . $price .'<small class="woocommerce-price-suffix"> zł</small></span>';
$display_price .= '</div><div>';
$display_price .= '<span>Cena brutto</span><span class="amount">' . $price_incl_tax .'<small class="woocommerce-price-suffix"> zł</small></span>';
$display_price .= '</span></div>';
$data['price_html'] = $display_price;

return $data;
}
add_filter( 'woocommerce_available_variation', 'edit_selected_variation_price', 10, 3);

如何在不选择任何款式的情况下显示最高价格?

1 个答案:

答案 0 :(得分:0)

我不完全理解你的问题,你想要什么价格的最高价格(含税和......)? 但是,当数组中有不同的价格(或作为松散变量)时,请考虑使用 PHP max() 函数: https://www.php.net/manual/en/function.max.php

这将返回最高值(希望这就是您所追求的)