如何从 WooCommerce 价格过滤器中排除可变价格?
How to exclude a variable price from the WooCommerce price filter?
我需要从价格过滤器中删除一个特定的可变价格,并按价格删除 WooCommerce 订单。
我有 4 个可变产品,我不想在价格过滤器中显示一个包含所有产品价格 $495 的可变属性。
我只是想隐藏这个特定的属性,这样它就不会被计入价格过滤器以及 wordpress 按价格排序。
谢谢。
您将需要这样的东西:
add_filter( 'woocommerce_sale_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_empty_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variable_sale_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variable_empty_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variation_sale_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variation_price_html', 'custom_remove_price_html', 20, 2 );
function custom_remove_price_html( $price, $product ) {
// if this is a product is a variable product.
if ( $product->is_type( 'variable' ) ) { // updated
// $price = '';
return;
}
return $price;
}
如果它不能如您所愿,您将需要微调函数内部的条件,以满足您的需要。
您必须将此代码片段添加到您的活动主题(或更好的活动子主题)的 functions.php
文件中。
我需要从价格过滤器中删除一个特定的可变价格,并按价格删除 WooCommerce 订单。
我有 4 个可变产品,我不想在价格过滤器中显示一个包含所有产品价格 $495 的可变属性。
我只是想隐藏这个特定的属性,这样它就不会被计入价格过滤器以及 wordpress 按价格排序。
谢谢。
您将需要这样的东西:
add_filter( 'woocommerce_sale_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_empty_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variable_sale_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variable_empty_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variation_sale_price_html', 'custom_remove_price_html', 20, 2 );
add_filter( 'woocommerce_variation_price_html', 'custom_remove_price_html', 20, 2 );
function custom_remove_price_html( $price, $product ) {
// if this is a product is a variable product.
if ( $product->is_type( 'variable' ) ) { // updated
// $price = '';
return;
}
return $price;
}
如果它不能如您所愿,您将需要微调函数内部的条件,以满足您的需要。
您必须将此代码片段添加到您的活动主题(或更好的活动子主题)的 functions.php
文件中。