How To Initiate A Redirect From A Shopify Checkout Validation App

Hello, I have followed the below tutorial and created a Shopify checkout validation app.

https://shopify.dev/docs/apps/checkout/validation/cart-checkout

Everything is working as expected, however, if the validation fails, instead of showing a message, I would like to redirect the customer to the cart page.

How would I go about acheiving this,

Please see simplified version of my code below:

extensions/cart-checkout-validation/src/index.js

// @ts-check
// Use JSDoc annotations for type safety
/**
 * @typedef {import("../generated/api").InputQuery} InputQuery
 * @typedef {import("../generated/api").FunctionResult} FunctionResult
 */
// The @shopify/shopify_function package will use the default export as your function entrypoint
export default
/**
 * @param {InputQuery} input
 * @returns {FunctionResult}
 */

(input) => {

    // The error
    const error = {
        localizedMessage:
            "This is a example message",
        target: "cart"
    };

    const errors = [];
    errors.push(error);

   if (true) {
     // TODO: Redirect customer to cart page
   }

    return {errors};
};

The error is showing as expected, but I would instead like to initiate a redirect.

I have been at this for hours with no success. Any help would be greatly appreciated.

Hi @SoapMatt ,

While we don’t currently provide direct support for Functions in this forum, the public [Shopify/function-examples GitHub repository] has an active [discussion board] that might be worth checking out.

Hope you have a great day