隐藏缺货 - "pre_get_post" 分类法以在商店页面上显示
Hide out of stock - "pre_get_post" taxanomy for visibility on shop page
在我的 WooCommerce 商店中,我启用了 "Hide out of stock items from the catalogue"。此选项会导致个别页面上的产品变体变得不可见。
我只想在归档页面(搜索、类别) 上应用 "Hide out of stock items from the catalogue" 选项 。
这是我的代码:
function featured_posts( $query ) {
if ( ! $query->is_main_query() ) return;
//What goes in here?
}
add_action( 'pre_get_posts', 'featured_posts' );
我怎样才能做到这一点?
谢谢
Try This
您必须检查页面以执行此操作,如下所示
function featured_posts( $query ) {
if(is_product_category() || is_search()){
if ( ! $query->is_main_query() ){
return;
}
}
....
}
add_action( 'pre_get_posts', 'featured_posts' );
在我的 WooCommerce 商店中,我启用了 "Hide out of stock items from the catalogue"。此选项会导致个别页面上的产品变体变得不可见。
我只想在归档页面(搜索、类别) 上应用 "Hide out of stock items from the catalogue" 选项 。
这是我的代码:
function featured_posts( $query ) {
if ( ! $query->is_main_query() ) return;
//What goes in here?
}
add_action( 'pre_get_posts', 'featured_posts' );
我怎样才能做到这一点?
谢谢
Try This
您必须检查页面以执行此操作,如下所示
function featured_posts( $query ) {
if(is_product_category() || is_search()){
if ( ! $query->is_main_query() ){
return;
}
}
....
}
add_action( 'pre_get_posts', 'featured_posts' );