Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] Cart Icon (Quantity Display)

Home Forums Support [Resolved] Cart Icon (Quantity Display)

Home Forums Support Cart Icon (Quantity Display)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1966853
    Juned

    Hi,

    I followed this trick of Ying and implemented it sucessfully at Mobile view: https://generatepress.com/forums/topic/footer-sticky-bar/#post-1669570

    (pls check in Mobile view)

    Now I need your help for: When added a product to basket, the sticky-bottom button’s icon should also display the quantity. Is it possible?

    Just like in this Mobil view (private):

    #1967004
    David
    Staff
    Customer Support

    Hi there,

    try this:

    1. Add this snippet to create a shortcode:

    function db_custom_cart_count() {
    
        ob_start();
    
    	if ( ! class_exists( 'WooCommerce' ) ) {
    		return;
    	}
    
    	if ( ! isset( WC()->cart ) ) {
    		return;
    	}
    
    	$no_items = '';
    
    	if ( ! WC()->cart->get_cart_contents_count() > 0 ) {
    		$no_items = 'no-items';
    	}
    
    	printf(
            '<span class="cart-contents"><span class="number-of-items %1$s">%2$s</span></span>',
            $no_items,
            WC()->cart->get_cart_contents_count()
        );
        return ob_get_clean();
    }
    add_shortcode('db_cart_count', 'db_custom_cart_count');

    2. Edit your button label and add: [db_cart_count]

    #1967086
    Juned

    Hello,

    Thanks for your response.

    1. I added the snippet via Code Snippets –> Run snippet everywhere.
    2. Where should I add “[db_cart_count]”?
    At button, I can see: HTML Anchor | ARIA Label | Additional CSS class(es) | Custom Attributes.

    Please suggest where should I put this: [db_cart_count]

    (I have linked Cart Page URL also with the button)

    Thanks in advance.

    #1967095
    David
    Staff
    Customer Support

    You add it as the button label, so when you select the button and you would normally add the button text, you add it in there. Make sure the Button text isn’t set to hidden.

    #1967117
    Juned

    Awesome. As always.

    🙂

    #1967125
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.