Archived topic
EDD Shopping Cart Quantity in Navigation
24 replies · Started by Michael on February 24, 2018
Hey guys - thanks for your continued support. I'm learning as I go.
Easy Digital Downloads has a code for Ajax enabled cart quantity updates. Currently, my site has a shopping cart icon in the navigation - I would like to add the quantity next to the cart as items are added (obviously). EDD has a code for this here -
https://docs.easydigitaldownloads.com/article/275-showing-the-cart-quantity-in-your-templates
I think I need to use hooks to achieve this? I'm running into a wall here as I'm not sure where to insert that code.
Thanks in advance for the help!
Hi there,
The easiest way would be to use this plugin: https://en-ca.wordpress.org/plugins/wp-menu-cart/
Otherwise you could try hooking it in:
add_action( 'generate_inside_navigation', 'tu_add_edd_cart_to_nav' );
function tu_add_edd_cart_to_nav() {
if ( ! function_exists( 'edd_get_checkout_uri' ) ) {
return;
}
?>
<a class="edd-cart" href="<?php echo edd_get_checkout_uri(); ?>">
Cart (<span class="header-cart edd-cart-quantity"><?php echo edd_get_cart_quantity(); ?></span>)
</a>
<?php
}
Thank you! Will see how the plugin works. If I was to hook it in, would I paste code that in the GP Hooks section of the plugin? And if so, which one? I thought there might be a generate_inside_navigation within the GP Hooks section but I don't see one.
Thanks again!
That hook is not included in the Hooks module (only the popular ones are included in there).
So try one of the methods here: https://docs.generatepress.com/article/adding-php/
Code Snippets is the easiest if you aren't using a child theme.
The plugin that you recommended Tom is excellent. If I can work out the kinks I think I will just use this.
I was able to use the hook provided (using code snippets) and create almost what I wanted, which was the shopping cart with the number of items in parenthesis. The trouble was getting the icon to center (heighth wise) as well as the styling of the number of items. Given my total newbness when it comes to this kind of thing, I think the plugin will do just fine.
Quick question - the plugin generates a cart with the number of items. I can align this to the left or right, however, when I align to the right (which is where I want it), it lists before the search icon. Preferably, the search icon is the first of my icons to display on the right, and the cart icon will be where my current cart icon is now. The link I provided in my first post should show this. The paid version allows custom CSS - will the menu-item-float-right send it past the search icon as it does with my other menu items that I float right? I hope I'm making sense...
Thanks again for the awesome support. Really happy I chose this theme.
Mike
Give this CSS a shot:
.main-navigation li.search-item,
.wpmenucart-display-right {
float: none !important;
display: inline-block;
}
#menu-navigation-bar {
text-align: right;
}
Let me know :)
Worked perfectly. Thank you so much!
You're welcome :)
Hi Tom
Thank you for your code but I have a problem.
How to hide the cart and view the number of products in the Menu ?
Thank you for your help
Olivier
[url=https://ibb.co/jQAZZT][img]https://preview.ibb.co/cqwmg8/Capture.png[/img][/url]
That icon shouldn't appear with my code above. Are you using this?: https://generatepress.com/forums/topic/edd-shopping-cart-quantity-in-navigation/#post-504902
Hi Tom
Yes I have a test but nothing appears, the code does not change anything... it's strange.
I use a child theme with function.php.
Thank you for your help
Any chance you can open a new support topic and include the URL to your website?
Thanks!
Hi
I can open a new topic but without the URL because the website is inside a secure server for the development.
I open a new topic with somes informations ?
Thank you
Hi Olivier,
Tom will need to see the site, if you raise a new topic you can add the URL to the Site URL field and only we can see that. If you need to send user login details you can use the Account Issue form here: https://generatepress.com/contact/ and provide a link to the topic.
Hi David
OK nice :)
A send a message
Thank you