【发布时间】:2023-03-16 03:11:01
【问题描述】:
在 WooCommerce 中,我已选中“可见性缺货”选项,但我需要某些产品类别保持可见,即使该选项已选中。
另一方面,主商店不显示该类别。为此,我使用了以下代码:
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'MYCATEGORY' ), // Don't show this category.
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
因为有可能这样做吗?
谢谢!
【问题讨论】:
标签: php wordpress woocommerce categories product