-1

I am trying to remove the shopping cart from the parents theme via the child theme's functions.php file. I could easily remove it from the parent's functions.php but we all know that is a no-no. Besides, the option to put it back should be available in the future. Unfortunately, the parent theme MAXSTORE was customized so a generic remove from woocommerce doesn't work. I have to hack the functions in MAXSTORE parent. But, I am not really that good at this. Can anyone show me how to do this?

p.s. Don't worry about the wishlist part. The theme config had a handy dandy checkbox to control its visibility ;)

Here is the function in question from the 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;
    }

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

EDIT

Being the front-end developer that I am, I managed to do it with CSS. A good solution, but not what I want and not what I asked so I won't answer my own question, instead I'll post it here for others to consider it

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
}

Thank you in advance

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140
  • I'm not sure I entirely understand the problem here, but can you just comment out that entire block of code? – Sgt AJ May 17 '16 at 23:40
  • I thought I was really clear. I'm actually really good at that. Ok, here is the thing, if I comment out the code, as soon as the theme gets an update, it will come back. That's why anytime you want to modify a theme, you should do it in the child theme. ;) – LOTUSMS May 17 '16 at 23:44
  • No worries. I haven't worked much with WordPress yet, so it's probably my fault. The parent code was all I could see, so I gave it a shot. :) Maybe someone else can help more. – Sgt AJ May 18 '16 at 00:04
  • :) I figured when you said "comment the code'. It's something we would normally do in a normal web development case. Unfortunately Wordpress is not that way. shrugs – LOTUSMS May 18 '16 at 00:05

1 Answers1

0

2 options:

  1. create a plugin... plugins are loaded before the theme so those if function exists is true because you have already defined the function, the function in the theme will not be defined (would cause a error if it was)...actually defining the functions in your child themes functions will also work, it is loaded before the parents functions.php

    function maxstore_head_wishlist(){
        //do nada....
    }
    
  2. remove the hooks you can from the child theme, will work for the second, not sure where the 1st function is hooked to, etc...

    remove_action( 'wp_ajax_yith_wcwl_update_single_product_list', 'maxstore_head_wishlist' );
    

the problem with the function above is its ajax, so there will be js to consider as well.

David
  • 5,897
  • 3
  • 24
  • 43