首页  >  问答  >  正文

从 WooCommerce 店面主题的主页中删除产品类别块

<p>我正在尝试删除 WooCommerce Storefront 主题主页中显示的默认产品类别部分块。</p> <p>我尝试通过在functions.php中使用几个钩子来删除该块,例如:</p> <pre class="brush:php;toolbar:false;">function remove_storefront_category() { remove_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper', 9); remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10); remove_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20); remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30); remove_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper_close', 31); remove_action( 'woocommerce_after_shop_loop', 'woocommerce_reset_loop', 999); } add_action( 'woocommerce_after_shop_loop', 'remove_storefront_category' );</pre> <p>但无论我尝试什么,此产品类别部分块都不会消失。</p> <p>我搜索了很多,只找到了有关隐藏特定类别的信息,但我想完全隐藏它。</p>
P粉908138620P粉908138620385 天前543

全部回复(1)我来回复

  • P粉322106755

    P粉3221067552023-09-04 11:21:56

    要从店面主题主页删除产品类别部分,您可以使用以下简单的代码片段:

    add_action( 'init', 'remove_storefront_home_product_categories', 10 );
    function remove_storefront_home_product_categories(){
        // Unhook storefront_product_categories() function from 'homepage' action hook
        remove_action( 'homepage', 'storefront_product_categories', 20 );
    }

    代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。

    回复
    0
  • 取消回复