Để 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é
Code loại trừ category ra khỏi trang shop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| 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/
Tham khảo thêm: http://docs.woothemes.com/document/exclude-a-category-from-the-shop-page/
Không có nhận xét nào:
Write nhận xét