Personalized checkout and custom promotions with Shopify Scripts
I'm trying to edit the code I found on https://community.shopify.com/c/shopify-design/site-access-add-age-verification-to-your-online-store...5 so that I can also check their state. I've got the state box entered, and it will pop up an alert, but I can't figure out how to make it so that only certain states are allowed in. We can only ship to certain states, so we want to make that known up front.
This is what I have so far for the function:
function stateCheck() {
var legal_state = {{ enter_state }}; // sets legal states
var state = parseInt(document.getElementById('bystate').value);
if ((bystate != legal_state)) {
{alert("this state is not legal. we can not sell to you.")}
} else {
var state = parseInt(document.getElementById('bystate').value);
if ((bystate = legal_state)) {
location.reload();
}
}
}
Above that I reference the values of the states that are legal. I only entered for for testing.
{% assign legal_state = 50 %}
<option value="50">WI</option>
The option value is listed in a drop down in a select area.
Any suggestions?
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025