Wooccommerce店面主题:remove_action不起作用



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

在我的儿童主题函数.php中,我添加了以下内容:

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调用似乎正在工作。排序和分页都消失了,只剩下产品网格本身。

尝试after_setup_theme操作挂钩。

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' );

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

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

最新更新