0
在2.4x之前,我使用此片段從目錄和產品頁面上的價格而不是最小 - 最大價格。Woocommerce 2.4x - 使用價格方法2.0的可變價格問題
add_filter('woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2);
add_filter('woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2);
function wc_wc20_variation_price_format($price, $product) {
// Main Price
$prices = array($product->get_variation_price('min', true), $product->get_variation_price('max', true));
$price = $prices[0] !== $prices[1] ? sprintf(__('From: %1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
// Sale Price
$prices = array($product->get_variation_regular_price('min', true), $product->get_variation_regular_price('max', true));
sort($prices);
$saleprice = $prices[0] !== $prices[1] ? sprintf(__('From: %1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
if ($price !== $saleprice) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}
但是,由於他們更新了整個變化邏輯,所以它似乎不再那麼好用了。我參考這個官方帖子:https://woocommerce.wordpress.com/2015/09/14/caching-and-dynamic-pricing-upcoming-changes-to-the-get_variation_prices-method/
任何提示如何解決這個問題?
參考: https://github.com/woothemes/woocommerce/blob/2.4.7/includes/class-wc-product-variable.php#L257