Javascript can be used to prevent entering a PO box in the shipping address fields when items cannot be shipped to a post office box.
To prevent entering PO Boxes in the shipping address, you can enter the following script in:
Commerce Setup > Order System > Checkout Screen – Text at the bottom of the Checkout screen
<script type="text/javascript">
var post_office_message = "We are unable to offer shipping to Post Office addresses for this order. Please enter your street address for the shipping address."
var po_regex = /^po.*box.*|^p.o..*box.*/i
function checkShipAddress(address){
if(po_regex.test(address)){
alert(post_office_message)
}
}
window.onload - function(){
document.billing.ShipAddress.onchange = function(){
checkShipAddress(this.value)
}
document.billing.ShipAddress2.onchange = function(){
checkShipAddress(this.value)
}
}
</script>
and the following code to:
Commerce Setup > Order System > Checkout Screen – Javascript added at start of built-in CheckIt function
var post_office_message = "We are unable to offer shipping to Post Office addresses for this order. Please enter your street address for the shipping address."
var po_regex = /^po.*box.*|^p.o..*box.*/i
if(po_regex.test(document.billing.ShipAddress.value)){
alert(post_office_message)
return(false)
}
if(po_regex.test(document.billing.ShipAddress2.value)){
alert(post_office_message)
return(false)
}
This will display the message defined as post_office_message in the script if a PO box is entered in the shipping address 1 or shipping address 2 fields and prevent the customer from checking out until it is removed. This message can be customized.
If you need to prevent the use of Box as well as PO Box (or P.O. Box) you can replace each instance of the line:
var po_regex = /^po.*box.*|^p.o..*box.*/i;
with:
var po_regex = /^box.*|^po.*box.*|^p.o..*box.*/i;