从 Woocommerce 挂钩中删除功能 [英] Removing functions from Woocommerce hooks

查看:30
本文介绍了从 Woocommerce 挂钩中删除功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能会为我打开一扇门,因为我缺少一些东西,所以请使用 WooCommerce 101;

This will probably open a door for me as there's something I'm missing so a WooCommerce 101 please;

WooCommerce 模板 archive-product.php 的一部分包含代码;

part of the WooCommerce template archive-product.php contains the code;

    <?php
            /**
             * woocommerce_before_shop_loop hook.
             *
             * @hooked woocommerce_result_count - 20
             * @hooked woocommerce_catalog_ordering - 30
             */
            do_action( 'woocommerce_before_shop_loop' );
        ?>

从这里,并阅读文档,它暗示了这一点;

From this, and reading the documentation, it implies that this;

remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );

应该从返回的产品类别中删除结果计数.只是没有.

should remove the result count from the product categories returned. Only it doesn't.

怎么了?

推荐答案

我想说你应该阅读 文档,但它遗漏了一个重要的部分.

I was going to say you should read the documentation but it is leaving an important part out.

remove_action() 不能直接调用,必须将其本身添加到动作挂钩中.动作钩子需要在删除动作之前出现.在这种情况下,我将只使用相同的钩子,但优先级更早(默认为 10,我使用了 1)

remove_action() cannot be called directly and must, itself, be added to an action hook. The action hook needs to come before the action being removed. In this case I would just use the same hook, but an earlier priority (default is 10, I've used 1)

function so_38878702_remove_hook(){
   remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
}
add_action( 'woocommerce_before_shop_loop', 'so_38878702_remove_hook', 1 );

这篇关于从 Woocommerce 挂钩中删除功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆