5 YEARS AGO
product page: purchase validation
I'd like to validate (via AJAX) that a user is permitted to purchase a product and if not, disable the "Add to cart" button in the product page and show some text explaining why they are not allowed to purchase the item.
I do not want to put products behind a Wix membership or password as I want prospective clients to see that the products exist and generate interest even if they aren't currently eligible to purchase.
If only I had access to the DOM...
if (!eligible(contact) {
// disable the addToCart button
document.querySelectorAll(`button[class*="AddToCart"], button[class^=" AddToCart"`)[0].disabled = true
// reduce the opacity of the AddToCart button
document.querySelectorAll(`button[class*="AddToCart"], button[class^=" AddToCart"`)[0].setAttribute('style', 'opacity:0.2')
// add subtext below the button explaining why
let warn = document.createElement('div')
warn.setAttribute('style', 'text-align:center;')
let warnSmall = document.createElement('small')
let warnText = document.createTextNode('Must be a member')
warn.appendChild(warnSmall)
warnSmall.appendChild(warnText)
document.querySelectorAll(`button[class*="AddToCart"], button[class^=" AddToCart"`)[0].parentElement.appendChild(warn)
}
Pending
Feature
1 Votes
Top Requests
-
Lorem Ipsum.
-
Lorem Ipsum.
-
Lorem Ipsum.
-
Lorem Ipsum.
Log in to your Wix account to leave a comment
Thanks for posting! Your comment will be shown once it’s reviewed.
Comments
Add your comments and suggestions here.