【问题标题】:woocommerce remove_action not working but add doeswoocommerce remove_action 不起作用,但 add 可以
【发布时间】:2017-12-28 02:17:29
【问题描述】:

我已将以下代码添加到我的functions.php 文件的底部,它们并没有从我的产品页面中删除这些函数。我直接从 content-single-product.php 页面复制了优先级编号,但仍然没有运气!

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5  );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price',10  );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt',20  );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart',30 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta',40 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_sharing' ,50);
remove_action('woocommerce_single_product_summary', 'WC_Structured_Data::generate_product_data()',60 );e

【问题讨论】:

    标签: php wordpress woocommerce product hook-woocommerce


    【解决方案1】:

    尝试以这种方式将它们包含在woocommerce_single_product_summary 动作挂钩中以较小优先级挂钩的自定义函数中:

    add_action('woocommerce_single_product_summary', 'customizing_single_product_summary_hooks', 2  );
    function customizing_single_product_summary_hooks(){
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_title', 5  );
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_rating', 10 );
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_price',10  );
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_excerpt',20  );
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart',30 );
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_meta',40 );
        remove_action('woocommerce_single_product_summary','woocommerce_template_single_sharing' ,50);
        remove_action('woocommerce_single_product_summary','WC_Structured_Data::generate_product_data()',60 );
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。

    这样应该可以工作

    【讨论】:

    • 不错的答案!从技术上讲,最小的优先级是PHP_INT_MIN,但这只是技术性的! :)
    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 2014-10-19
    • 2022-12-16
    • 2017-07-02
    • 2011-01-16
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多