Re: Code for minimum order value

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
447 32 120

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

Founder, Regios Discounts app (4.9 stars, 54 reviews)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer

KarmaChime
Excursionist
50 2 0

Yes, you can set a minimum order value using the PayRules: Hide Payment Methods app. Here's how you can do it:

 

  1. Set Minimum Order Value for Checkout:
  2. Choose all the payment methods you want to restrict (PayPal, Stripe etc) until the minimum order value is reached from the "Select payment methods" field.
  3. In the "Cart total" section, set the minimum limit to 250 like the screenshot below.

minimum-250.png

 

This setup will ensure that customers need to have a cart total of at least $250 before being able to see and use the specified payment methods. This way, you can enforce a minimum order value without needing multiple apps.