简体   繁体   English

仅在 Woocommerce 的商店存档页面上隐藏缺货产品

[英]Hide out of stock products only on shop archive pages in Woocommerce

I am trying to hide out of stock products only from Shop page, but keep them on the separate category page.我试图仅从商店页面隐藏缺货产品,但将它们保留在单独的类别页面上。

Woocommerce settings allows only to choose either to show out of stock products or to hide them completely. Woocommerce 设置只允许选择显示缺货产品或完全隐藏它们。

How to hide out of stock products only on shop archive pages in Woocommerce?如何仅在 Woocommerce 的商店存档页面上隐藏缺货产品?

Updated: Using a custom function hooked in woocommerce_product_query_meta_query filter hook, targeting non "out of stock" products on shop archive pages only:更新:使用挂在woocommerce_product_query_meta_query过滤器钩子中的自定义函数,仅针对商店存档页面上的非“缺货”产品:

add_filter( 'woocommerce_product_query_meta_query', 'shop_only_instock_products', 10, 2 );
function shop_only_instock_products( $meta_query, $query ) {
    // Only on shop archive pages
    if( is_admin() || is_search() || ! is_shop() ) return $meta_query;

    $meta_query[] = array(
        'key'     => '_stock_status',
        'value'   => 'outofstock',
        'compare' => '!='
    );
    return $meta_query;
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。

Tested and works测试和工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 WooCommerce 类别页面上隐藏缺货产品? - How can I hide out of stock products on WooCommerce category pages? 仅在具有 Elementor 的小部件上隐藏缺货 WooCommerce 产品 - Hide out of stock WooCommerce products only on a widget with Elementor 如何在 WooCommerce 商店页面上隐藏库存少于 2 的产品 - How to hide products with stock less than 2 on WooCommerce shop page 在 WooCommerce 中隐藏缺货的相关产品 - Hide out of stock related products in WooCommerce 如何在WooCommerce商店和档案页面隐藏价格高于1的产品 - How to hide products with price higher than 1 on WooCommerce shop and archives pages 在Woocommerce存档页面中将“销售”徽章替换为“缺货” - Replace “Sale” badge by “Out of Stock” in Woocommerce archive pages 在 Woocommerce 中使用自定义元数据隐藏“缺货”产品 - Hide “out of stock” products with custom meta data In Woocommerce WooCommerce:按属性过滤产品并在变体缺货时隐藏产品 - WooCommerce: filter products by attribute and hide product if variation is out of stock WooCommerce单品页面隐藏“缺货”相关产品 - Hide “out of stock” related products on WooCommerce single product page 仅在woocommerce商店/类别页面上隐藏“添加到购物车”按钮 - Hide 'add to cart' button ONLY on woocommerce shop/category pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM