我们需要通过品牌设置网站范围的曲奇过滤器。
WooComerce有内置的品牌分类法。
在开始登陆页面时,用户将从多个品牌中选择一个。之后,用户只通过选定的品牌观看网站上的产品。如果用户将访问品牌url (www.example.com/ brand / brand -second),则需要将筛选器更改为另一个品牌,并仅按最后选定的品牌显示产品。其他不允许展示的产品(其他品牌或没有品牌)。
对于实现这一点,有什么想法?
发布于 2020-01-19 04:53:06
我认为您可以尝试将可见品牌保留在cookie中,并使用woocommerce_product_query或pre_get_posts过滤器根据该cookie值进行筛选。
每次用户访问该品牌URL时,都会更改cookie值。
发布于 2020-01-25 09:29:53
我为我的问题找到了解决办法!
function filter_products_by_brand( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'brand',
'field' => 'slug',
'terms' => array( 'dobro' ), // Don't display products in the clothing category on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'pre_get_posts', 'filter_products_by_brand' );https://stackoverflow.com/questions/59801321
复制相似问题