I have not tested this at all—let me know if it doesn't actually work.
Created
August 10, 2016 05:03
-
-
Save brandonsheppard/502a2f51069821a1df74ef1014ae9f61 to your computer and use it in GitHub Desktop.
Show a modal to query the shoppers country if they aren't in Australia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="modal fade" id="shipCountryModal" tabindex="-1" role="dialog" aria-labelledby="shipCountryModalLabel"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
<form method="post" action="[@url@]"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
<h4 class="modal-title">Hello, international shopper!</h4> | |
</div> | |
<div class="modal-body"> | |
<p>It looks like you're not shopping from Australia, where we are based—select your country below and we'll ensure you're not seeing prices which include Australia-specific taxes.</p> | |
<div class="form-group"> | |
<select class="form-control" name="ship_country"> | |
[%countries%] | |
[%PARAM *body%] | |
<option value="[@country_code@]" [%if [@country_code@] eq [@ship_country@]%]selected[%/if%]>[@country_name@]</option> | |
[%/param%] | |
[%/countries%] | |
</select> | |
</div> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |
<input type="submit" class="btn btn-primary" value="Save changes" /> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
[%site_value id:'footer_javascript'%] | |
<script src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js" type="text/javascript"></script> | |
<script type="text/javascript" src="//cdn.neto.com.au/assets/neto-cdn/jquery_cookie/jquery.cookie.js"></script> | |
<script> | |
$(document).ready(function(){ | |
// This function checks your location and triggers the "Where are you?" modal if you aren't in Australia | |
var queryCountry = (function () { | |
var onSuccess = function (geoipResponse) { | |
var country = geoipResponse.country.iso_code | |
var popupstatus = $.cookie('popupstatus'); | |
// if it's not Australia... | |
if(popupstatus != 'popped' && country != 'AU') { | |
// Tries to set the country select to be the country detected. | |
$('[name="ship_country"]').val(country); | |
// Open the modal | |
$('#shipCountryModal').modal(); | |
// Disable this modal from showing again | |
$.cookie('popupstatus', 'popped'); | |
} | |
}; | |
var onError = function (error) { | |
var country = none | |
}; | |
return function () { | |
geoip2.country(onSuccess, onError); | |
}; | |
}()); | |
queryCountry(); | |
}); | |
</script> | |
[%/site_value%] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment