禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

如何在woocommerce商品页中排除某些分类的产品

禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

要想从woocommerce商店页面中的特定类别中排除产品,可以使用以下代码:

/**

 * Remove products from shop page by category

 *

 */

function woo_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( 'shoes' ),

'operator' => 'NOT IN'

)));




}




 remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );




}

add_action( 'pre_get_posts', 'woo_custom_pre_get_posts_query' );

 

将PHP代码放在主题或子主题functions.php文件的底部。

0 个评论

 
联系
目前暂停一切业务,客服消息可能不会及时回复,谢谢理解。
在线咨询
    在线咨询
    禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。