Using Shopify information on a Thank You page

This solution requires the use of a Shopify plugin. Orders placed against the campaign must be sending the orders back to Shopify.

Global Scripts can be used to place the code on multiple Thank You pages within a funnel or a domain.

Orders are sent to Shopify on the Thank You page. After the order is successfully sent it is possible to retrieve the Shopify customer ID and order ID for use on the page. To take advantage of this functionality, edit the Thank You page(s) and place the following code in the <body> of the page. Adjust lines 10-14 as needed to handle the Shopify information.

<script type="text/javascript">
	const orderQueryUrl = "https://live-api.checkoutchamp.com/providersApi/V1/ClubMembership/OrderQueryByOrderId";
	// Set ccClientOrderQueryIterations numeric value type variable with number of order query iteraton needed to fetch required order details, currently set to 5
	const ccClientOrderQueryIterations = 5;
	var ccClientOrderCheckInterval, ccClientOrderQueryCallCount = 1;
	// function to set order data details, function accepts an object type parameter containing order details
	function ccSetOrderDetails(orderData) {
		try {
			if (orderData) {
				//orderData.emailAddress
				//orderData.phoneNumber
				//orderData.orderId
				//orderData.vendorOrderId (shopify order ID)
				//orderData.clientCustomerId (shopify customer ID)
			}
		} catch(err) {err;}
	}
	async function ccClientOrderQuery(payload, orderData) {
		try {
			if (payload && orderData) {
				if (ccClientOrderQueryCallCount > ccClientOrderQueryIterations) {
					ccSetOrderDetails(orderData);
					return;
				}
				ccClientOrderQueryCallCount++;
				const data = await httpMethod(orderQueryUrl, payload);
				if (data && data.result === "SUCCESS" && data.message && data.message.vendorOrderId) {
					ccSetOrderDetails(data.message);
					return;
				}
				setTimeout(function() { ccClientOrderQuery(payload, orderData); }, 3000);
			}
		} catch (err) {
			setTimeout(function() { ccClientOrderQuery(payload, orderData); }, 3000);
		}
	}
    function ccClientInitializeOrderSearchInterval() {
		if (window.location.path !== "blank") {
			ccClientOrderCheckInterval = setInterval( function() {
			try {
					const orderDataString = sessionStorage.getItem("orderData");
					const orderData = (orderDataString && JSON.parse(orderDataString)) || {};
					if (httpMethod && orderData.orderId) {
						clearInterval(ccClientOrderCheckInterval);
						const payload = JSON.stringify({ "orderId": orderData.orderId, "finalizeTransaction": 1 });
						ccClientOrderQuery(payload, orderData);
					}
				} catch (err) {err;}
			}, 3000);
		}
	}
	ccClientInitializeOrderSearchInterval();
</script>

Last updated