从子主题functions.php中删除菜单中的购物车

时间:2016-05-17 22:38:34

标签: php wordpress codex

我正在尝试通过子主题的functions.php文件从父主题中删除购物车。我可以很容易地从父母的functions.php中删除它,但我们都知道这是禁止的。此外,将来可以选择将其取回。不幸的是,父主题MAXSTORE是自定义的,因此从woocommerce中删除通用功能并不起作用。我必须破解MAXSTORE parent中的函数。但是,我对此并不是那么擅长。谁能告诉我怎么做?

P.S。不要担心愿望清单部分。主题配置有一个方便的花花公子复选框来控制其可见性;)

以下是来自parent functions.php

的有问题的函数
////////////////////////////////////////////////////////////////////
// WooCommerce header cart
////////////////////////////////////////////////////////////////////
if ( !function_exists( 'maxstore_cart_link' ) ) {

    function maxstore_cart_link() {
        ?>  
        <a class="cart-contents text-right" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'maxstore' ); ?>">
            <i class="fa fa-shopping-cart">
                <span class="count"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
            </i>
            <span class="amount-title hidden-sm hidden-xs"><?php echo _e( 'Cart ', 'maxstore' ); ?></span>
            <span class="amount-cart"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span> 
        </a>
        <?php
    }

}
if ( !function_exists( 'maxstore_head_wishlist' ) ) {

    function maxstore_head_wishlist() {
        if ( function_exists( 'YITH_WCWL' ) ) {
            $wishlist_url = YITH_WCWL()->get_wishlist_url();
            ?>
            <div class="top-wishlist text-right">
                <a href="<?php echo esc_url( $wishlist_url ); ?>" title="Wishlist" data-toggle="tooltip">
                    <i class="fa fa-heart"><div class="count"><span><?php echo yith_wcwl_count_products(); ?></span></div></i>
                </a>
            </div>
            <?php
        }
    }

}
add_action( 'wp_ajax_yith_wcwl_update_single_product_list', 'maxstore_head_wishlist' );
add_action( 'wp_ajax_nopriv_yith_wcwl_update_single_product_list', 'maxstore_head_wishlist' );

if ( !function_exists( 'maxstore_header_cart' ) ) {

    function maxstore_header_cart() {
        ?>
        <div class="header-cart-inner">
            <?php maxstore_cart_link(); ?>
            <ul class="site-header-cart menu list-unstyled">
                <li>
                    <?php the_widget( 'WC_Widget_Cart', 'title=' ); ?>
                </li>
            </ul>
        </div>
        <?php
        if ( get_theme_mod( 'wishlist-top-icon', 0 ) != 0 ) {
            echo maxstore_head_wishlist();
        }
        ?>
        <?php
    }

}
if ( !function_exists( 'maxstore_header_add_to_cart_fragment' ) ) {
    add_filter( 'woocommerce_add_to_cart_fragments', 'maxstore_header_add_to_cart_fragment' );

    function maxstore_header_add_to_cart_fragment( $fragments ) {
        ob_start();

        maxstore_cart_link();

        $fragments[ 'a.cart-contents' ] = ob_get_clean();

        return $fragments;
    }

}
////////////////////////////////////////////////////////////////////

修改

作为我的前端开发人员,我设法用CSS做到了。一个很好的解决方案,但不是我想要的,而不是我所要求的,所以我不会回答我自己的问题,而是我会在这里发布,供其他人考虑

li#wpmenucartli {
   display: none;  //hides the menu cart list item
}

.navbar-inverse .navbar-nav > li:nth-last-child(2) > a:after {
   content: '';   //gets rid of the trailing dash on the second to last list item to pretend it is the actual last item
   border-right:none;  //if you have a border, this does the same as above
}

提前谢谢

1 个答案:

答案 0 :(得分:0)

2个选项:

  1. 创建一个插件...插件在主题之前加载,所以如果函数存在则为true,因为你已经定义了函数,主题中的函数将不会被定义(如果是的话会导致错误)...实际定义子主题函数中的函数也可以工作,它在父函数.php

    之前加载
    function maxstore_head_wishlist(){
        //do nada....
    }
    
  2. 从子主题中删除你可以使用的钩子,第二个就可以工作,不知道第一个函数被连接到哪里等等......

    remove_action( 'wp_ajax_yith_wcwl_update_single_product_list', 'maxstore_head_wishlist' );
    
  3. 上面函数的问题是它的ajax,所以也会考虑js。

相关问题