Re: Hide checkout button conditionally

How can I conditionally hide the checkout button without page refresh?

flaquitqm
Visitor
1 0 0

I want to hide checkout buttom if cart.total_price  is under $2000. I could do it with a liquid conditional in cart-template.liquid, so when user goes to his cart and its total is under $2000, checkout button is hidded. My problem is that I know that in this solution a page refresh is needed. I want to hide or show checkout button when user increase or decrease a cart item quantity without refresh the page. It's that posible? I am using Debut theme.

Replies 2 (2)

juansmartdev
Shopify Partner
85 17 24

Hi, @flaquitqm

You could achieve that using the AJAX Api for the cart. 
https://shopify.dev/api/ajax/reference/cart

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Senior Shopify Developer.
◦ Contact me at: juandev.martinez@gmail.com

gr_trading
Shopify Partner
2045 149 206

Hi @flaquitqm ,

 

You have to edit cart.js find the below line

fetch(`${routes.cart_change_url}`, { ...fetchConfig(), ...{ body } })

 

and write your condition in its success state.

 

Hope it helps...

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee