【问题标题】:Remove Header/Footer from cart page Storefront theme从购物车页面店面主题中删除页眉/页脚
【发布时间】:2020-06-20 06:00:57
【问题描述】:

我想借助自定义函数或钩子从店面 woocommerce 主题的购物车页面中删除页眉和页脚。

您能否建议我应该使用哪个功能来实现这一目标?

谢谢。

【问题讨论】:

    标签: wordpress woocommerce customization hook-woocommerce storefront


    【解决方案1】:

    你可以做两种方式。一种是使用 CSS,另一种是使用钩子。正如您特别询问钩子一样,我将提供钩子的代码。

    您需要找出店面主题的页眉和页脚中使用了哪些钩子。然后在店面子主题中,创建一个functions.php文件(如果不存在,很可能确实存在),然后添加以下代码:

    function remove_header_from_cart(){
        if( is_cart() ){
    
            remove_action( 'storefront_page', 'storefront_page_header', 10 );
            remove_action( 'storefront_before_content', 'storefront_header_widget_region', 10 );
            remove_action( 'storefront_header', 'storefront_header_container', 0);
            remove_action( 'storefront_header', 'storefront_skip_links', 5 );
            remove_action( 'storefront_header', 'storefront_site_branding', 20 );
            remove_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
            remove_action( 'storefront_header', 'storefront_product_search', 40 );
            remove_action( 'storefront_header', 'storefront_header_container_close', 41 );
            remove_action( 'storefront_header', 'storefront_primary_navigation_wrapper', 42 );
            remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
            remove_action( 'storefront_header', 'storefront_header_cart', 60 );
            remove_action( 'storefront_header', 'storefront_primary_navigation_wrapper_close', 68 );
        }
    }
    add_action('wp_head','remove_header_from_cart');
    
    function remove_footer_from_cart(){
        if( is_cart() ){
            remove_action( 'storefront_footer', 'storefront_footer_widgets', 10 );
            remove_action( 'storefront_footer', 'storefront_credit', 20 );
        }
    }
    add_action('wp_head','remove_footer_from_cart');
    

    【讨论】:

    • 这完美地回答了这个问题。但是,在某些情况下,子主题也是可能接收更新的第三方组件,在这种情况下,functions.php 文件有被覆盖的风险。如果是这种情况,请使用自定义插件或像 github.com/woocommerce/theme-customisations 这样的帮助程序,这是一个像主题/子主题扩展一样“表现”的插件。希望这会有所帮助!
    猜你喜欢
    • 2023-01-19
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2017-06-05
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    相关资源
    最近更新 更多