我需要从价格过滤器中删除一个特定的可变价格,并按价格删除 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
文件中。