[Resolved] Cart icon customize

Home Forums Support [Resolved] Cart icon customize

Home Forums Support Cart icon customize

  • This topic has 28 replies, 3 voices, and was last updated 3 years ago by Tom.
Viewing 14 posts - 16 through 29 (of 29 total)
  • Author
    Posts
  • #673961
    ZZZ

    Hey Tom,

    didnt work :/ The cart doesn’t show the “quantity” when it is empty. It only shows quantity when items are inside the cart, 1 item and above.

    When it is empty, it doesn’t show zero.

    #674495
    Tom
    Lead Developer
    Lead Developer
    #674953
    ZZZ

    Hey Tom,

    Still doesn’t work. Here are the images with 1 item in cart, and empty cart.

    #675573
    Tom
    Lead Developer
    Lead Developer
    #675599
    ZZZ

    Hey Tom,

    I’m not sure what went wrong.. it’s still not working. However on initial load it works. 1second later it’ll jump and then disappears. This does not happen for 1 item and above.

    Please see screenshots.

    #675600
    Tom
    Lead Developer
    Lead Developer

    Aha, replace this function as well:

    add_filter( 'woocommerce_add_to_cart_fragments', 'tu_wc_cart_link_fragment' );
    function tu_wc_cart_link_fragment( $fragments ) {
    	global $woocommerce;
    	$fragments['.cart-contents span.number-of-items'] = ( WC()->cart->get_cart_contents_count() > 0 ) ? '<span class="number-of-items">' . wp_kses_data( WC()->cart->get_cart_contents_count() ) . '</span>' : '<span class="number-of-items">0</span>';
    	return $fragments;
    }
    #675632
    ZZZ

    still no luck Tom… it’s jumps again after 1 second.

    #675782
    Tom
    Lead Developer
    Lead Developer

    I just tested it and it’s working on my end.

    These are the functions I used:

    function tu_custom_wc_cart_link() {
        ob_start();
        $count = WC()->cart->get_cart_contents_count();
        ?>
        <a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class="cart-contents" title="<?php esc_attr_e( 'View your shopping cart','generate-woocommerce' ); ?>">
            <?php _e( 'Enquiry','generate-woocommerce' );?>
    
            <?php
            if ( $count > 0 ) {
                echo sprintf ( _n( '<span class="number-of-items">%d</span>', '<span class="number-of-items">%d</span>', $count ), $count );
            } else {
                echo '<span class="number-of-items">0</span>';
            }
            ?>
        </a>
        <?php
        return ob_get_clean();
    }
    
    function tu_custom_wc_menu_cart( $nav, $args ) {
        if ( $args->theme_location == 'primary' && generatepress_wc_get_setting( 'cart_menu_item' ) ) {
            return sprintf(
                '%1$s
                <li class="wc-menu-item %4$s" title="%2$s">
                    %3$s
                </li>',
                $nav,
                esc_attr__( 'View your shopping cart','generate-woocommerce' ),
                tu_custom_wc_cart_link(),
                is_cart() ? 'current-menu-item' : ''
            );
        }
    
        // Our primary menu isn't set, return the regular nav
        return $nav;
    }
    
    function tu_custom_wc_mobile_cart_link() {
    	if ( function_exists( 'generatepress_wc_get_setting' ) && ! generatepress_wc_get_setting( 'cart_menu_item' ) ) {
    		return;
    	}
    	?>
    	<div class="mobile-bar-items wc-mobile-cart-items">
    		<?php do_action( 'generate_mobile_cart_items' ); ?>
    		<?php echo tu_custom_wc_cart_link(); ?>
    	</div><!-- .mobile-bar-items -->
    	<?php
    
    }
    
    add_filter( 'woocommerce_add_to_cart_fragments', 'tu_wc_cart_link_fragment' );
    function tu_wc_cart_link_fragment( $fragments ) {
    	global $woocommerce;
    	$fragments['.cart-contents span.number-of-items'] = ( WC()->cart->get_cart_contents_count() > 0 ) ? '<span class="number-of-items">' . wp_kses_data( WC()->cart->get_cart_contents_count() ) . '</span>' : '<span class="number-of-items">0</span>';
    	return $fragments;
    }
    
    add_action( 'after_setup_theme','tu_remove_wc_cart_item' );
    function tu_remove_wc_cart_item() {
        remove_filter( 'wp_nav_menu_items','generatepress_wc_menu_cart', 10, 2 );
        add_filter( 'wp_nav_menu_items','tu_custom_wc_menu_cart', 10, 2 );
    
        remove_action( 'generate_inside_navigation','generatepress_wc_mobile_cart_link' );
        remove_action( 'generate_inside_mobile_header','generatepress_wc_mobile_cart_link' );
    
        add_action( 'generate_inside_navigation','tu_custom_wc_mobile_cart_link' );
        add_action( 'generate_inside_mobile_header','tu_custom_wc_mobile_cart_link' );
    }
    #675872
    ZZZ

    hey Tom, yes it is. I disabled all plugins and WP rocket seems to be the one affecting it! I’ll go ask them.

    Btw, is there a possibility of using GP secondary menu in Woocommerce?

    #675916
    Tom
    Lead Developer
    Lead Developer

    What would you want to do with the secondary menu? Move the cart icon into it?

    #675936
    ZZZ

    Hi Tom,

    I would like to put it into the sidebar. But it doesn’t allow this option for woocommerce pages. So just wondering if there’s a way to do it because GP menu is smoother and cleaner as compared to Elementor nav menu πŸ™‚

    #676458
    Tom
    Lead Developer
    Lead Developer

    The Secondary Nav has sidebar locations in the Navigation Location option. Have you tried those yet?

    Let me know πŸ™‚

    #676889
    ZZZ

    Hey Tom,

    That’s alright, Im using woocommerce with elementor, they might not allow the theme menu insertion in it.

    Thanks for the the whole topic on the cart thingy! Cheers!

    #677276
    Tom
    Lead Developer
    Lead Developer
Viewing 14 posts - 16 through 29 (of 29 total)
  • You must be logged in to reply to this topic.