d
Topic
Anna Shopify Partner
Posts:
11
9 days ago

Open Ajax cart drawer automatically

Hi.

I am looking for a way of triggering the ajax cart automatically if someone goes to /cart, rather than loading the /cart template.

So, if someone types the cart url into the browser, they will go to the site homepage, but with the drawer trigger so it opens automtically, as if they have clicked on cart in the site navigation.

Is there a way to do this?

I've used Timber as a starting point for my theme.

Thank you.

i
Replies
Posts:
31
9 days ago

If someone manually enters /cart into the browser address bar, then server will return the cart page. You can hardly prevent it from not happenning. But you can modify the cart page to redirect user back to the home page, with a special parameter to trigger cart popup.

Drive more sales with free Promo Bar @ https://apps.shopify.com/sticky-promo-bar
Anna Shopify Partner
Posts:
11
9 days ago

Yes, that is what I am after. Do you know how to do it? I have got a redirect working but don't know how to trigger the cart popup.

Posts:
31
8 days ago

Do you know to write simple code in JavaScript? If yes, then look at at Shopify theme documentation for their Ajax API reference. The cart and the popop are 2 separate parts.

Drive more sales with free Promo Bar @ https://apps.shopify.com/sticky-promo-bar
Anna Shopify Partner
Posts:
11
6 days ago

Do you mean here? https://help.shopify.com/themes/development/getting-started/using-ajax-api

I can't find anything in those pages relating to triggering the drawer so that it opens.

Yes - I can write javascript. Maybe it's a case of just adding a class to the drawer so it apears open, but I would rather trigger the function that exists already if there is one?

 

Posts:
31
6 days ago

I don't think there is a built-in function to open cart in the way you want. It should be theme's function. Though you can implement a popup yourself with cart content responded from https://help.shopify.com/themes/development/getting-started/using-ajax-api#get-cart

Or you can find to trigger a click event on the cart icon, it depends on theme you are using.

Drive more sales with free Promo Bar @ https://apps.shopify.com/sticky-promo-bar
Anna Shopify Partner
Posts:
11
6 days ago

It's a custom theme I have built based on the Timber theme.