Environment: Shopify 2.0
Extension Name: cart-checkout-validation
Function Name: cart-checkout-validation
Function Language: Rust
Objective
I’m building a Shopify app extension using Rust (Function API) to validate cart behavior based on metafield-defined rules at the shop level.
My goal is to:
Display informative validation messages on both the Product Detail Page (PDP) and Cart Page
Prevent checkout if metafield rules are violated (only on the Cart Page)
Allow products to be added to cart even if rules are not met (on the PDP)
Shop Metafield Definition (JSON)
{
“metafields”: [
{
“type”: “json”,
“value”: “{"cartTotal":{"minT":[{"min":"200","s":1,"ut":["all"]}],"maxT":[{"max":"500","s":1,"ut":["all"]}]},"cartQty":{"minQ":[{"min":"10","s":1,"ut":["all"]}],"maxQ":[{"max":"20","s":1,"ut":["all"]}]}}”
}
]
}
This metafield defines rules for:
Cart Total Amount (cartTotal) — minimum and maximum allowed cart total.
Cart Quantity (cartQty) — minimum and maximum number of items in the cart.
Current Issues
PDP Blocking Add to Cart
Even if the cart total or quantity conditions are not met, I want users to be able to add products to the cart.
But currently, products cannot be added if the metafield conditions are not satisfied.
Cart Page Restrictions
On the cart page, I want to prevent checkout if the rules (min/max cart total or quantity) are violated.
However, currently:
The cart quantity selector doesn't allow increasing or decreasing quantities if conditions are not met.
Products cannot be removed from the cart.
Expected Behavior
On PDP:
Allow adding products to cart regardless of rules.
Show non-blocking validation messages if rules are violated.
On Cart Page:
Allow cart updates (quantity, removal).
Show blocking validation messages only on checkout, not on every interaction (e.g., quantity update or remove).
What I Need Help With
How can I modify my Rust function or frontend logic to:
Allow product additions from PDP even when rules are violated?
Prevent checkout (but not cart updates) if cart total/quantity rules fail?
Allow product removal and quantity updates from the cart page without strict blocking?
Thanks in advance for any guidance or examples from those who’ve implemented similar logic using Shopify Functions and metafields!
