Remove State Options From Estimate Shipping Dropdown - Shopify Cart Page
Shopify’s Estimate Shipping Calculator shows all of the US territories and there is no way to remove from the settings menu, so this code cycles through the options and removes any of the undesired options.
This technique was first used on the LPGA cart page.
Open cart.liquid and add the following code at the bottom at the file. Note: This code requires jquery.
Update the undesired_options array with the options that need removed.
<script>
$( document ).ready(function() {
console.log('removing non-states from dropdown');
//add indexOf method to Array if not supported by browser
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (obj, fromIndex) {
if (fromIndex == null) {
fromIndex = 0;
} else if (fromIndex < 0) {
fromIndex = Math.max(0, this.length + fromIndex);
}
for (var i = fromIndex, j = this.length; i < j; i++) {
if (this[i] === obj)
return i;
}
return -1;
};
}
var undesired_options = [
'American Samoa',
'Armed Forces Americas',
'Armed Forces Europe',
'Armed Forces Pacific',
'Federated States of Micronesia',
'Guam',
'Marshall Islands',
'Northern Mariana Islands',
'Palau',
'Puerto Rico',
'Virgin Islands'
];
$('#address_province option').each(function( index, option ){
//if undersired_options contains current option's value
if( undesired_options.indexOf( option.value ) > -1 ){
option.remove();
}
});
});
</script>