Wordpress版本: 4.6.1
Woocommerce版本: 2.6.4
使用标准的woocommerce时,您可以添加具有不同价格值的可变产品.Woocommerce显示该产品低于产品标题的最低和最高价格.像这样:€50 - €100
我将以下代码添加到我的functions.php文件中以禁用变量产品的此行为:
/** Hide Variable prices */
add_filter( 'woocommerce_variable_sale_price_html', 'bbloomer_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'bbloomer_variation_price_format', 10, 2 );
function bbloomer_variation_price_format( $price, $product ) {
if (is_product()) {
return $product->get_price();
} else {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( …Run Code Online (Sandbox Code Playgroud)