Redirect to specific page after payment

Hi,

I am using wix stores and would like to redirect a member to a specific page after they have paid for a product. Is there a way to do this?

I have looked at using the continued browsing link but that wont work for what I need as other users will see the link.

Is this possible with code? If so, can someone point me in the right direction?

Many thanks

Create an After Order Paid Event

  • Go to the “Backend” section of your site’s code panel.
  • Create a new file called events.js.
  • Add the following code to handle the order paid event and redirect the user:
// In events.js

import { redirectUserToPage } from 'backend/customRedirect';

export function wixStores_onOrderPaid(event) {
    const { orderId, userId } = event;

    // Check if the userId exists to ensure it's a member
    if (userId) {
        redirectUserToPage(userId);
    }
}

Create a Backend Function to Handle Redirect

  • Create another backend file called customRedirect.jsw and add the following code:
// In customRedirect.jsw

import wixUsers from 'wix-users-backend';
import wixLocation from 'wix-location';

export function redirectUserToPage(userId) {
    // Define the URL of the page you want to redirect the user to
    const redirectUrl = '/specific-page';

    // Get the current user's ID
    const currentUser = wixUsers.currentUser;

    // Check if the user is logged in and the userId matches
    if (currentUser.loggedIn && currentUser.id === userId) {
        // Perform the redirection
        wixLocation.to(redirectUrl);
    }
}

Ensure you replace '/specific-page' with the actual URL of the page you want to redirect users to.

Tell us, if its work for you.