Hide Cart Until Item Is Added

The original library, featuring hundreds of free copy-and-paste plugins for Squarespace. These legacy plugins are preserved as they were originally released and are available as-is. For no-code plugins with visual editing and live previews, explore the current plugin library.
Overview
Hide the shopping cart until an item is been added to it. This plugin uses code injection and works with Squarespace 7.0 (Brine template family).
Plugin Delivery
This is a free plugin from the original Ghost Plugins library. Copy the code below and paste it into your Squarespace site. No purchase or account needed.
Squarespace Compatibility & Requirements
Compatibility notes preserved from the original release.
Customizable Options
- From your Squarespace account, go to Site Code Injection. Copy and paste the code below into the Footer Code Injection box.
- You do not need to change any values or properties.
- This plugin comes with an Unlimited Use License. View License Terms
Install
Legacy plugins install by hand, there is no Plugin Studio build for this one.
- 1Copy the code from the Code Documentation section below.
- 2In Squarespace, open Website, Pages, Website Tools, Custom CSS for CSS, or Settings, Advanced, Code Injection for HTML and JavaScript.
- 3Paste the code, save, then refresh your site to see the plugin running.
Code Documentation
JavaScript
<script>
/**
* Hide Cart until items in the cart
*/
(function () {
var carts = [].slice.call(document.querySelectorAll('.Cart'));
carts.forEach(function(cart) {
hideCart(cart);
});
/**
* Hide Cart
*/
function hideCart(cart) {
var cartQty = cart.querySelector('.sqs-cart-quantity');
// Handler
function handler(target) {
if (target.innerHTML === '0') {
cart.setAttribute('hidden', '');
} else {
cart.removeAttribute('hidden');
}
}
// Observer handler
var observer = new MutationObserver(function(mutations) {
handler(mutations[0].target);
});
// Hide/show the cart when the page is loaded
handler(cartQty);
// Hide/show the cart when an item was added/removed
observer.observe(cartQty, { childList: true });
}
})();
</script>Script Settings
Values you can adjust at the top of the script to change how the plugin behaves.
[].slice.call(document.querySelectorAll('.Cart'))cart.querySelector('.sqs-cart-quantity')new MutationObserver(function(mutations) {FAQ
Answers to common questions about setup, customization, and troubleshooting.
Is this plugin free?
Yes. Legacy plugins are free to use on any site, no account or purchase needed.
Will it work on my Squarespace version?
Legacy plugins were built for the version noted in Squarespace Compatibility & Requirements and are provided as-is. Newer platform changes may require small tweaks.
Can I customize it?
Yes. Edit the values in Script Settings or override the selectors listed under Classes and Styling in your Custom CSS.
Do you support legacy plugins?
Legacy plugins are no longer updated. For maintained plugins with Plugin Studio and ongoing support, browse the current plugin library.
Changelog
A history of updates released for this plugin.
Original release
Archived exactly as it shipped in the original plugin library. No further updates are planned for legacy plugins.
Recommended
Want the current Ghost experience?
Explore the current plugin library for plugins with live previews, built-in customization options, Plugin Studio editing, easier installation, and ongoing updates designed for the latest Ghost experience.
Browse Current Plugins →Community
Give claps, share your site, and talk with others using this plugin.
0 claps
Show thanks for this plugin.
Give Claps and Join The Conversation
Sign in to give claps and join the conversation.
Loading…
