Introduction

The Validations service plugin (formerly SPI) allows site owners and collaborators to validate a site visitor's cart and checkout. For example, you can validate a specific line item’s quantity if the quantity per order is limited. Site owners and collaborators can either write their own custom validation logic, or integrate with a 3rd-party validations provider.

Wix eCommerce calls getValidationViolations() to retrieve any violations in a site visitor's cart and checkout. The custom validation plugin code validates the request, and returns any validation violation data in a site visitor's cart and checkout (using the structure provided by Wix eCommerce). If there aren't any validation violations, the endpoint should return an object containing an empty array. Site visitors can see validation violations in their cart and checkout pages. For example, see the images below:

The image below shows a cart page with both a general validation violation warning and a line item validation violation warning.

Cart page warnings

The images below show a checkout page with both a general validation violation error and a line item validation violation error.

The general violation error appears at the top of the checkout page:

Checkout page errors

The error appears again above the Place Order & Pay button at the end of the page. The button is disabled until the errors are resolved.

Checkout page errors

For a step-by-step tutorial, see Validation Violations service plugin.

Future functionality includes validating products and orders.

Before you begin

By default, the Validations service plugin only validates a site visitor's checkout. If you want to also validate a site visitor's cart, set the validateInCart parameter to true in the service plugin's config file.

To add a service plugin

  1. Add the plugin to your site.
  2. Update the getConfig() function in the -config.js file that is added to your site during step 1.
  3. Update the getValidationViolations() function in the .js file that is added to your site during step 1.

Use Cases

With the Validations service plugin you can define the validations for a cart and checkout that fit your site's needs. Possible validations include:

  • Minimum subtotal amount to qualify for free shipping.
  • Age of a customer before they proceed to checkout.
  • Specific items to ship only to specific regions.
  • Restrict purchases to site members only.
  • Close checkout on certain days.

Terminology

TermDefinition
SeverityHow severe the violation is. The violations are shown on the cart and checkout pages. A warning is displayed as yellow, and allows a site visitor to proceed with caution. An error is displayed as red, and doesn't allow a site visitor to proceed with the eCommerce flow.
Subscription OptionA store owner can create subscriptions to sell their products on a recurring basis. A line item can be a subscription.
TargetTarget location on a checkout or cart page where the violation will be displayed. The target violation can either be in a particular lineItem, or in an other area of the cart or checkout page.
ViolationsA list of any validation violations in a site visitor's cart or checkout.
Did this help?