首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Woocommerce Storefront主题: remove_action不工作

Woocommerce Storefront主题: remove_action不工作
EN

Stack Overflow用户
提问于 2021-04-20 01:10:25
回答 2查看 82关注 0票数 1

我正在尝试更改我的商店页面上的默认内容。我的网站使用的是WooCommerce和Storefront主题的一个子主题。

在我的子主题的functions.php中,我添加了以下内容:

代码语言:javascript
复制
function remove_catalog_defaults() {
    remove_action( 'homepage', 'storefront_homepage_content', 10 );
    remove_action( 'homepage', 'storefront_product_categories', 20 );
    remove_action( 'homepage', 'storefront_recent_products', 30 );
    remove_action( 'homepage', 'storefront_featured_products', 40 );
    remove_action( 'homepage', 'storefront_popular_products', 50 );
    remove_action( 'homepage', 'storefront_on_sale_products', 60 );
    remove_action( 'homepage', 'storefront_best_selling_products', 70 );
    
    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_before_shop_loop', 'storefront_sorting_wrapper', 9 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
    remove_action( 'woocommerce_before_shop_loop', 'storefront_woocommerce_pagination', 30 );
    remove_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper_close', 31 );
}

add_action( 'storefront_before_content', 'remove_catalog_defaults', 5);

但商店页面上的所有内容仍在加载。你可以在这里看到:https://staging.embrace.gallery/all-artwork/

首先加载我想要加载的内容(4行产品),然后在它下面加载默认的商店页面。如何删除所有默认内容?

编辑:一些remove_action调用似乎起作用了。排序和分页都消失了,只剩下产品网格本身。

EN

回答 2

Stack Overflow用户

发布于 2021-04-20 01:20:28

尝试after_setup_theme操作挂钩。

代码语言:javascript
复制
function remove_catalog_defaults() {
    remove_action( 'homepage', 'storefront_homepage_content', 10 );
    remove_action( 'homepage', 'storefront_product_categories', 20 );
    remove_action( 'homepage', 'storefront_recent_products', 30 );
    remove_action( 'homepage', 'storefront_featured_products', 40 );
    remove_action( 'homepage', 'storefront_popular_products', 50 );
    remove_action( 'homepage', 'storefront_on_sale_products', 60 );
    remove_action( 'homepage', 'storefront_best_selling_products', 70 );
    
    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_before_shop_loop', 'storefront_sorting_wrapper', 9 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
    remove_action( 'woocommerce_before_shop_loop', 'storefront_woocommerce_pagination', 30 );
    remove_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper_close', 31 );
}
add_action( 'after_setup_theme', 'remove_catalog_defaults' );
票数 0
EN

Stack Overflow用户

发布于 2021-04-20 01:47:16

这不是一个基于代码的解决方案,但它适用于我的目的:

我创建了一个虚拟页面,并告诉WooCommerce这是商店页面。然后,WooCommerce停止尝试在实际的商店页面上加载所有额外的产品。这不会弄乱面包屑,因为我把它去掉了。我还用自己设计的自定义页面替换了Category页面,所以我将尝试更改产品页面上的所有默认链接,以转到我自己的页面,而不是WooCommerce页面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67166421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档