Prevent Entering PO Box as Shipping Address in ShopSite

Forum Forums Tutorials Prevent Entering PO Box as Shipping Address in ShopSite

This topic contains 0 replies, has 1 voice, and was last updated by  Anonymous 9 years, 2 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #48796

    Anonymous
    Participant

    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;

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.