# Manipulating cart buttons/objects

**URL:** <https://forum.readymag.com/t/manipulating-cart-buttons-objects/333>\
**Category:** Custom code\
**Created:** [June 9, 2022, 9:36am UTC](https://forum.readymag.com/t/manipulating-cart-buttons-objects/333 "2022-06-09T09:36:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://forum.readymag.com/u/chris)\
**Post date:** [June 9, 2022, 9:36am UTC](https://forum.readymag.com/t/manipulating-cart-buttons-objects/333/1 "2022-06-09T09:36:20Z")

</div>

Hi all,

I’m wondering what the best way to manipulate/override ‘add to cart’ buttons is? In general, for buttons, what is the best way to override the ‘onclick’ method?

Is there a way I can grab the global cart/session object in order to manipulate it?

Thanks for any help/insight!

---

<div class="post-metadata">

**Author:** ![HEADLESS.HORSE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/headless.horse/32/144_2.png) [@HEADLESS.HORSE](https://forum.readymag.com/u/HEADLESS.HORSE)\
**Post date:** [June 13, 2022, 2:02pm UTC](https://forum.readymag.com/t/manipulating-cart-buttons-objects/333/2 "2022-06-13T14:02:31Z")

</div>

Hi Chris,

We have played around with this! I have attached some experimental code that we started. Maybe it’s a starting point for you. You could trigger the cart to add it’s ‘.show’ class? @neueMeta any ideas?

```auto
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>

  <script>
    $(document).ready(function() {
      $('[data-id="PASTE WIDEGET ID HERE"]').click(function() {
        $('#cart-sidebar').toggleClass("show");
      });
    });

    $(".e-com-cart-button > div > div").clone().appendTo("#MAYBE YOU COULD APPEND THE CART NUMBER TO ANOTHER ELEMENT?");
  </script>

```

---

<div class="post-metadata">

**Author:** ![HEADLESS.HORSE](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/headless.horse/32/144_2.png) [@HEADLESS.HORSE](https://forum.readymag.com/u/HEADLESS.HORSE)\
**Post date:** [June 13, 2022, 7:14pm UTC](https://forum.readymag.com/t/manipulating-cart-buttons-objects/333/3 "2022-06-13T19:14:04Z")

</div>

The last piece of code was us looking to see if we could still keep the number of items in cart and append it to another element.

---

<div class="post-metadata">

**Author:** ![neueMeta](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/neuemeta/32/92_2.png) [@neueMeta](https://forum.readymag.com/u/neueMeta)\
**Post date:** [June 14, 2022, 11:03am UTC](https://forum.readymag.com/t/manipulating-cart-buttons-objects/333/4 "2022-06-14T11:03:45Z")

</div>

well, what exactly do you want to achieve/change… it might be possible to change behaviour/naming/whatsoever. I´m not that into e-commerce integration and don´t have a project where I can check things out right now but I can give tipps on how to approach a change in the default behaviour/etc…

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://forum.readymag.com/u/chris)\
**Post date:** [June 15, 2022, 5:30am UTC](https://forum.readymag.com/t/manipulating-cart-buttons-objects/333/5 "2022-06-15T05:30:00Z")

</div>

Hi, so tbh I don’t know what I can do yet. Headless.Horse’s answer was enough. I just needed an object for me to log to console and inspect, that I way I can see what I can do (or not do).

In the end we may have to just build or own backend using the Stripe client library and integrate with that somehow.

I’d like to close this case now, but don’t know how!
