Your insights drive our innovation — submit product suggestions or report an issue below.
PeakCommerce customers want to be able to validate if a user has had a trial previously before granting them a new trial.
We've developed a snippet of code that can be inserted into the header of the ecommerce page template or it can be added to the global ecommerce header if you wish to add it to all templates.
<script>
$(document).ready(function() {
var allowSubscription = true;
// Search through the cookies to see if one exists for our purposes
$.each(document.cookie.split(/; */), function() {
var splitCookie = this.split(‘=’);
if (splitCookie[0].startsWith(‘pc-sub-’)) {
var cookie = JSON.parse($.cookie(splitCookie[0]));
if (cookie.pageId == pageId) {
allowSubscription = false;
// TODO: this line makes the redirect to the appropriate page
//window.location.href = ‘https://google.com’;
}
}
});
// In case the redirect doesn't work -- disable and hide all buttons
if (!allowSubscription) {
setTimeout(function() {
$(‘.btn-primary’).prop(‘disabled’, true).css(‘display’, ‘none’);
}, 50);
}
// Listener to detect when the user successfully checks out
$(window).bind(‘hashchange’, function() {
var signupForm = homevm.signup_home_vm().signup_form_vm();
var stepCode = signupForm.stepCode();
if (stepCode == ‘THANK_YOU’) {
var finalModel = signupForm.getFinalModel();
var nonce = ‘pc-sub-’ + finalModel.pageId;
var p = {
pageId: finalModel.pageId,
email: finalModel.email,
products: JSON.parse(finalModel.products),
url: window.location.href,
timestamp: Date.now()
}
$.cookie(nonce, JSON.stringify(p), {path: ‘/’});
}
});
});
</script>
The javascript file is attached to this thread. If you have suggestions or alterations to the code, please add comments below.