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
  • Views 455
  • 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

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, 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...
Quote

 

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 ?

 

A little late with an answer.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

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.