How to add minimum order value code to my website?

eadesigns
Visitor
2 0 0

Hi! I'm hoping someone can help me figure out how to add code to my site that would require customers to reach a certain $ amount before they are able to check out. I'm moving the wholesale section of my business to a seperate website and was hoping to be able to add a minimum order value without having so many different apps... currently my minimum is 250! I'm using the Dawn theme! Thank you for any help!!:)

Replies 2 (2)

tobebuilds
Shopify Partner
222 12 67

Hi Eadesigns,

 

There are at least 2 ways to do this.

 

Option 1 (preferred): Use the Cart and Checkout Validation Function API

 

The Cart and Checkout Validation Function API is a new Shopify API that allows developers to add custom rules, and prevent customers from checking out if they don't meet certain conditions. The conditions can be based on the contents/subtotal of the cart, or even the customer's location.

 

The main benefit of using this API is that it's compatible with multiple Shopify features, like the checkout, cart, and Storefront API. This is your best bet for new code.

 

However, there are some drawbacks:

  • Because it's a new API, it's only available in custom apps, not public apps. If you're building this for your own store, that's okay, but you can't reuse the app on another store.
  • It's not available in the online store cart yet. But if I understand correctly, it is compatible with the online store checkout, so you can still prevent customers from ordering if their cart subtotal is too low.

 

Option 2: Use the Shopify AJAX API + JavaScript in your theme code

 

This method will only work with your online store.

 

You can use the AJAX API to get the contents of a customer's cart (get /{locale}/cart.js). After fetching the response, you can evaluate a condition in your code, and if it's true, you can then add some HTML to the cart to reflect on the error. You can also set the "Check out" button as disabled to prevent them from proceeding to the next step.

 

The tricky part will be listening for cart updates and reacting automatically, as I don't think the AJAX API has any way to listen for a stream of cart update events. You can use the JS MutationObserver API, but exactly what to put it in it will depend on your specific theme.

 

This option also won't work if your customer has disabled JavaScript in their browser. And you also can't use this method to edit the checkout page.

 

Let me know if you have any other questions or concerns.

 

- Tobe Osakwe

ArrayArtisan
Tourist
50 0 2

You can hide payment methods based on the cart's total value, like setting a minimum of $250, using the KlinKode PayRules app. It allows you to configure conditions to control payment option visibility, helping to enforce your minimum order requirement indirectly.

 

Explore the app: https://apps.shopify.com/klinkode-payrules

 

- Control payment methods visibility at checkout by KlinKode PayRules app.
- You can join in our Facebook group for Shopify help.