Local Delivery Postcodes in WooCommerce

September 19, 2013

I’ve been trying to set up a website for somebody who wants to offer free delivery in Derbyshire and Nottinghamshire. They have provided a list of postcodes that they want to offer free delivery to. WooCommerce currently has support for providing postcodes with wildcards – for example NG2* will allow free delivery for any postcode starting NG2. Great!

However, this didn’t quite work how I needed it to. When entering the postcode NG20 1AA it gave me free delivery. The NG20 postcode region is quite a long way out from NG2 and free delivery should not be offered. So, I programmed in a workaround that allows postcodes to be specified in a more precise way.

Instead of a * to indicate any letters/numbers, I can now use underscores to specify each character. For example, NG1___ is how I am giving my allowed postcodes. Now the delivery postcode needs to be NG1 followed by 3 letters or numbers. NG1 1AA will match but NG10 1AA will not.

Being committed to open source, I submitted the extra code back to WooCommerce who have accepted the merge for inclusion in the next release.

View my code on Github