-1

我正在尝试通过子主题的 functions.php 文件从父主题中删除购物车。我可以轻松地将其从父函数的 functions.php 中删除,但我们都知道这是一个禁忌。此外,将来应该可以选择将其放回原处。不幸的是,父主题 MAXSTORE 是自定义的,因此从 woocommerce 中通用删除不起作用。我必须破解 MAXSTORE 父级中的函数。但是,我真的不擅长这个。谁能告诉我如何做到这一点?

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

这是来自父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
}

先感谢您

4

1 回答 1

0

2个选项:

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

    function maxstore_head_wishlist(){
        //do nada....
    }
    
  2. 从子主题中删除您可以使用的钩子,将适用于第二个,不确定第一个函数挂钩的位置,等等...

    remove_action( 'wp_ajax_yith_wcwl_update_single_product_list', 'maxstore_head_wishlist' );
    

上面这个函数的问题是它的ajax,所以还要考虑js。

于 2016-05-18T00:13:16.163 回答