less than a minute read • Updated 5 hours ago
Embed a customer portal in Webstudio
Easily embed Foxy Commerce's customer portal into any page in your Webstudio website. Once embedded, customers can view order history, manage subscriptions, and more... right inside of your Webstudio website.
Overview
Foxy's drop-in customer portal lets customers view order history, manage subscriptions, and update billing or shipping details directly on your Webstudio site.
Try It Out
Live Demo: https://foxy-commerce.wstd.io/ (admin / webstudio)
View Project: https://p-bf1b0ea7-031b-42b0-88bc-71d0d227defe.apps.webstudio.is/?authToken=dda31c89-bea7-4d7d-af23-0b7f9952a46c&mode=preview
Enable the customer portal
Add the required scripts
<script type="module">
import 'https://cdn-js.foxy.io/elements@1/foxy-customer-portal.js';
const I18nElement = customElements.get('foxy-i18n');
const i18nBase = 'https://cdn-js.foxy.io/elements@1/translations';
I18nElement.onResourceFetch((ns, lang) => fetch(`${i18nBase}/${ns}/${lang}.json`));
</script>Install the customer portal element
<foxy-customer-portal base="https://CHANGE.foxycart.com/s/customer/">
</foxy-customer-portal>Give customers access
Link to the customer portal page from anywhere on your site. Whether new customers can create an account at checkout is controlled by the Customer registration toggle under Settings > Customer Portal > Features.
Style the customer portal
The portal uses the Lumo theme. Only the Light theme is currently supported, though you can adjust it for a dark background.
Enable single sign-on
SSO keeps a customer logged into the portal and checkout at the same time.
html
<script>
function parseJWT(token) {
let base64Url = token.split(".")[1];
let base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
let jsonPayload = decodeURIComponent(
atob(base64)
.split("")
.map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
})
.join("")
);
return JSON.parse(jsonPayload);
}
function getSSOUrl() {
// Look for a cookie
var value = "; " + document.cookie;
var parts = value.split("; " + "fx.customer.sso" + "=");
if (parts.length == 2) return decodeURIComponent(parts.pop().split(";").shift());
// Look for localstorage
try {
let sessionStore = JSON.parse(localStorage.getItem("session"));
if (sessionStore && sessionStore.hasOwnProperty("jwt")) {
let sessionData = parseJWT(sessionStore.jwt);
let expires =
Math.floor(new Date(sessionStore.date_created).getTime() / 1000) + sessionStore.expires_in;
if (
expires > Math.floor(Date.now() / 1000) &&
sessionData.hasOwnProperty("customer_id") &&
sessionStore.hasOwnProperty("sso")
) {
return sessionStore.sso;
}
}
} catch (error) {
console.log("Error trying to get SSO URL:", error);
}
return false;
}
function getUrlParameter(name) {
return new URLSearchParams(location.search).get("fcsid");
}
if (getSSOUrl()) {
window.location.replace(getSSOUrl() + "&fcsid=" + getUrlParameter("fcsid"));
} else {
window.location.replace(
"https://FOXY_SUBDOMAIN/checkout?fc_customer_id=0×tamp=1893456000&fc_auth_token=SECRET_OUTPUT&fcsid=" +
getUrlParameter("fcsid")
);
}
</script>Extend the customer portal
The portal can be extended with custom functionality. Contact Foxy if you have a specific use case in mind.
Notes
Only Foxy customer accounts can log into the portal; whether new customers can register is controlled by the Customer registration toggle
Changing the Universal store secret invalidates the token in this snippet, so it will need to be regenerated
Session lifespan (default 4 weeks) controls how long a customer stays logged in without activity, set under Settings > Customer Portal > Security settings