【问题标题】:Hiding breadcrumbs on cart page in woocommerce with storefront theme在具有店面主题的 woocommerce 中的购物车页面上隐藏面包屑
【发布时间】:2016-01-05 13:52:36
【问题描述】:

我正在尝试使用店面的子主题隐藏面包屑。这是我在 functions.php 中的代码,但是,在购物车页面上时条件不会触发。删除条件会导致隐藏面包屑

add_action('init', 'remove_shop_breadcrumbs' );
function remove_shop_breadcrumbs()
{
    if ( is_cart()) 
    {
        remove_action( 'storefront_content_top', 'woocommerce_breadcrumb',  10 );
    }
}

从我能读到的所有内容来看,这是正确的,店面是否用自己的代码替换了这个条件,从而导致失败?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您的代码触发得太早了。在运行查询之前触发 init 钩子,因此 is_cart() 将不起作用。请改用wp 操作。

    改变这个:

    add_action('init', 'remove_shop_breadcrumbs' );
    

    到这里:

    add_action( 'wp', 'remove_shop_breadcrumbs' );
    

    【讨论】:

    • 谢谢,现在可以使用了。这很有趣,因为我实际上是从 woothemes 的文档中获得了 init 钩子!
    猜你喜欢
    • 2020-06-06
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    相关资源
    最近更新 更多