Jump to content

Javascript code after the Cart is loaded

Recommended Posts

Hello,

At the moment of $(document).ready(..., the Cart is not loaded, below is the page HTML. So the cart is rendered by some next-to-run Javascript.

I need to run own Javascript code *after* the Cart has been rendered.

How can I do that ? Should I wait after some custom event ?

Thank you !

<div class="system-page">
            <div id="sqs-cart-root">
  <script type="application/json">
    
    {"cart":{...CART_CONTENTS_AS_JSON.}}
  </script>
  <div id="sqs-cart-container"></div>
</div>
          </div>

Link to comment
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

9 hours ago, AndreiGh said:

Hello,

At the moment of $(document).ready(..., the Cart is not loaded, below is the page HTML. So the cart is rendered by some next-to-run Javascript.

I need to run own Javascript code *after* the Cart has been rendered.

How can I do that ? Should I wait after some custom event ?

Thank you !

<div class="system-page">
            <div id="sqs-cart-root">
  <script type="application/json">
    
    {"cart":{...CART_CONTENTS_AS_JSON.}}
  </script>
  <div id="sqs-cart-container"></div>
</div>
          </div>

The following code works fine on my testing

$(document).ready(function() {
  const cart = $('.showOnDesktop .icon--cart[href *="cart"]')[0];
  console.log(cart);
})

Try and let me know how it goes

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment

That code retrieves the floating cart icon, not the actual cart contents, on the "cart" page (the products added in the cart, the "checkout" button) <-- these cart HTML is the one I want to modify (the DIVs with class cart-container, cart-summary).

Thank you !

Edited by AndreiGh
Link to comment
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.