- This topic has 28 replies, 3 voices, and was last updated 5 years, 6 months ago by Tom.
-
AuthorPosts
-
September 10, 2018 at 8:41 pm #673961ZZZ
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.
September 11, 2018 at 9:04 am #674495TomLead DeveloperLead DeveloperJust adjusted the function, can you try now?: https://generatepress.com/forums/topic/cart-icon-customize/#post-673917
September 11, 2018 at 10:11 pm #674953ZZZHey Tom,
Still doesn’t work. Here are the images with 1 item in cart, and empty cart.
September 12, 2018 at 9:18 am #675573TomLead DeveloperLead DeveloperGrr, WooCommerce not making it easy on us.
Another try: https://generatepress.com/forums/topic/cart-icon-customize/#post-673917
September 12, 2018 at 9:38 am #675599ZZZHey 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.
September 12, 2018 at 9:40 am #675600TomLead DeveloperLead DeveloperAha, 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; }
September 12, 2018 at 9:52 am #675632ZZZstill no luck Tom… it’s jumps again after 1 second.
September 12, 2018 at 1:07 pm #675782TomLead DeveloperLead DeveloperI 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' ); }
September 12, 2018 at 5:17 pm #675872ZZZhey 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?
September 12, 2018 at 7:29 pm #675916TomLead DeveloperLead DeveloperWhat would you want to do with the secondary menu? Move the cart icon into it?
September 12, 2018 at 8:35 pm #675936ZZZHi 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 π
September 13, 2018 at 8:34 am #676458TomLead DeveloperLead DeveloperThe Secondary Nav has sidebar locations in the Navigation Location option. Have you tried those yet?
Let me know π
September 13, 2018 at 10:39 pm #676889ZZZHey 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!
September 14, 2018 at 8:16 am #677276TomLead DeveloperLead DeveloperNo problem! π
-
AuthorPosts
- You must be logged in to reply to this topic.