Custom cart trigger

Updated on 18th June 2022 in Existing Websites

Out of the box, Shoprocket will load a ready to use basket / shopping cart into your page, along with a button (or trigger) to open the cart.

You may wish to add your own cart icon or button into your website header or navigation, which can be easily done by adding a javascript onclick event.

Once you've added your own button, link or icon into your page, bind a javascript click event to it, which will fire the "toggle cart" function on click:

<button onclick="Shoprocket.cart.toggle()">toggle cart</button>

The above example will create a basic button element, with the onlick event of "Shoprocket.cart.toggle()" - when a user clicks this button, the cart will open (or close if it's already open)

Once you have your own cart trigger working, you can hide the default Shoprocket trigger with some custom CSS like this:

<style> body .sr-element .sr-cart-trigger { display: none; } </style>
view raw hide-cart.css hosted with ❤ by GitHub

You can try this live demo of a JS button here:

You can also manually trigger opening the cart via URL params by appending #/~/cart to the end of your page URL. We also add/remove this URL param automatically when opening/closing the cart.

To create your own cart trigger button that doesn't need custom JS, you can simply set the href value to be /#/~/cart, like this:

Can’t find what you’re looking for?

Chat with us 👋

or contact us on help@shoprocket.io


as featured in
Added to cart
  • Your cart is currently empty
Shipping
Billing

Pay with Paypal


Once you click on button you will redirect to Paypal

15:00
Bitcoin QR code
Amount
Address
Automatic Discount 0.00
SUBTOTAL 0.00
Shipping
0.00
TAX
Got a coupon code? - 0.00
Apply Remove
0.00
Add a comment for the seller
Save
Payment by:
GRAND TOTAL 0.00