Loại trừ các sản phẩm trong một category ra khỏi trong shop của woocommerce

Để loại trừ category nào đó ra khỏi trang shop của woocommerce bạn chỉ cần thêm đoạn code sau vào file functions.php trong theme của bạn là ok nhé

Loại trừ các sản phẩm trong một category ra khỏi trong shop của woocommerce

Code loại trừ category ra khỏi trang shop

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( 'cat1','cat2' ), // Don't display products in the knives category on the shop page
 'operator' => 'NOT IN'
 )));
 }
 remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}

Các bạn thay cat1, cat2 bằng các slug của category mà bạn muốn loại trừ nhé

Chúc các bạn thành công ^^
Tham khảo thêm: http://docs.woothemes.com/document/exclude-a-category-from-the-shop-page/

5/5 - (2 votes)
  • Bình luận
Sản phẩm nổi bật của Toản
x