【发布时间】:2016-06-06 22:38:58
【问题描述】:
我需要从价格过滤器和 WooCommerce 订单中按价格删除一个特定的可变价格。
我有 4 个可变产品,我不想在价格过滤器中显示一个包含所有产品价格 $495 的可变属性。
我只是想隐藏这个特定属性,这样它就不会被计入价格过滤器以及按价格排序的 wordpress 中。
谢谢。
【问题讨论】:
标签: php wordpress woocommerce product price
我需要从价格过滤器和 WooCommerce 订单中按价格删除一个特定的可变价格。
我有 4 个可变产品,我不想在价格过滤器中显示一个包含所有产品价格 $495 的可变属性。
我只是想隐藏这个特定属性,这样它就不会被计入价格过滤器以及按价格排序的 wordpress 中。
谢谢。
【问题讨论】:
标签: php wordpress woocommerce product price
你需要这样的东西:
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;
}
如果它不能按您的意愿工作,您需要微调函数内部的条件,以满足您的需求。
您必须将此代码 sn-p 添加到您的活动主题(或更好的活动子主题)的 functions.php 文件中。
【讨论】: