我希望产品存档页面在默认情况下显示与特定属性值相对应的产品。
示例
属性: pa_condition
术语:新的,使用的,关闭的
开店时,我只想看到新产品。
但是有两种语言。所以我想,这个条件应该适用于属性id。
这是怎么做到的?
发布于 2017-11-08 15:09:40
更新:您可以尝试这个挂钩函数:
add_filter( 'woocommerce_product_query_tax_query', 'custom_product_query_tax_query', 10, 2 );
function custom_product_query_tax_query( $tax_query, $query ) {
if( is_admin() ) return $tax_query;
// Define HERE the product attribute and the terms
$taxonomy = 'pa_condition';
$terms = array( 'New', 'Used', 'Closeout' ); // Term names
// Add your criteria
$tax_query[] = array(
'taxonomy' => $taxonomy,
'field' => 'name', // Or 'slug' or 'term_id'
'terms' => $terms,
);
return $tax_query;
}代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。
测试和工作。
但是我不确定这些术语的翻译,所以您应该要求将它们添加到查询中的第二个$tax_query[]数组中,以便查询已翻译的术语…。
官方参考资料:查询~分类学参数
https://stackoverflow.com/questions/47182661
复制相似问题