- This topic has 9 replies, 4 voices, and was last updated 1 year, 4 months ago by David.
-
AuthorPosts
-
October 18, 2021 at 12:54 am #1966853Juned
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):
October 18, 2021 at 3:59 am #1967004DavidStaffCustomer SupportHi 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]
October 18, 2021 at 5:35 am #1967086JunedHello,
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.
October 18, 2021 at 5:42 am #1967095DavidStaffCustomer SupportYou 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.
October 18, 2021 at 6:10 am #1967117JunedAwesome. As always.
🙂
October 18, 2021 at 6:18 am #1967125DavidStaffCustomer SupportGlad to be of help!
September 8, 2022 at 5:46 am #2336942xinghuiHello, David, I added the short code to the button text as you said, but it still does not display, the custom code is the one you wrote before that shows the number of products that I used directly
code :
if ( has_term( ‘dummy’, ‘product_tag’ ) ) {// Get Parent Category and its count
$taxonomy = ‘product_cat’;
$cat = get_the_terms( $post->ID, $taxonomy )[0];
$count = (int) $cat->count;// Loop through children categories
$child_cats = get_term_children( $cat->term_id, $taxonomy);
foreach ($child_cats as $child_cat) {
$term = get_term( $child_cat, $taxonomy );
$count +=$term->count;
}printf(
‘%2$s <span class=”counter”>(%3$s)<span>‘,
$catLink = get_term_link( $cat , $taxonomy ),
$catName = $cat->name,
$count
);}
my problem image :September 8, 2022 at 6:54 am #2336998DavidStaffCustomer SupportHi there,
i replied to your topic here:
Please reply to the other topic.
November 7, 2022 at 7:24 am #2404785kernfunkeHi David,
thank you very much for this great solution. I just have two questions:
1. Is there a way to blend out the number count if nothing is in the cart?
2. The count is not updated as long as the page is not reloaded. How can I add AJAX update? In WooCommerce->Product->General the hook for AJAX support is set.Thanks a lot in advance!
November 8, 2022 at 3:25 am #2405978DavidStaffCustomer SupportHi there,
I don’t have a shortcode that supports Ajax.
if you require Ajax then you would need to use the GP Premium option to add the menu cart to the Navigation.
It can be set in Customizer > Layout > Woocommerce. And it has an option to set it to display the Number of Items. -
AuthorPosts
- You must be logged in to reply to this topic.