Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added wildcard support to local delivery postcodes. Closes #1477.

  • Loading branch information...
commit 1d95fef681421252bb464805912a91abab4243f1 1 parent 8c65efe
@mikejolley mikejolley authored
Showing with 32 additions and 9 deletions.
  1. +31 −9 classes/shipping/class-wc-local-delivery.php
  2. +1 −0  readme.txt
View
40 classes/shipping/class-wc-local-delivery.php
@@ -125,7 +125,7 @@ function init_form_fields() {
'codes' => array(
'title' => __( 'Zip/Post Codes', 'woocommerce' ),
'type' => 'textarea',
- 'description' => __( 'What zip/post codes would you like to offer delivery to? Separate codes with a comma.', 'woocommerce' ),
+ 'description' => __( 'What zip/post codes would you like to offer delivery to? Separate codes with a comma. Accepts wildcards, e.g. P* will match a postcode of PE30.', 'woocommerce' ),
'default' => ''
),
'availability' => array(
@@ -179,15 +179,37 @@ function is_available( $package ) {
// If post codes are listed, let's use them.
$codes = '';
- if($this->codes != '') {
- foreach(explode(',',$this->codes) as $code) {
- $codes[] = $this->clean($code);
+ if ( $this->codes != '' ) {
+ foreach( explode( ',', $this->codes ) as $code ) {
+ $codes[] = $this->clean( $code );
}
}
-
- if (is_array($codes))
- if ( ! in_array($this->clean( $package['destination']['postcode'] ), $codes))
+
+ if ( is_array( $codes ) ) {
+
+ $found_match = false;
+
+ if ( in_array( $this->clean( $package['destination']['postcode'] ), $codes ) )
+ $found_match = true;
+
+ // Wildcard search
+ if ( ! $found_match ) {
+
+ $customer_postcode = $this->clean( $package['destination']['postcode'] );
+ $customer_postcode_length = strlen( $customer_postcode );
+
+ for ( $i = 0; $i <= $customer_postcode_length; $i++ ) {
+
+ if ( in_array( $customer_postcode, $codes ) )
+ $found_match = true;
+
+ $customer_postcode = substr( $customer_postcode, 0, -2 ) . '*';
+ }
+ }
+
+ if ( ! $found_match )
return false;
+ }
// Either post codes not setup, or post codes are in array... so lefts check countries for backwards compatability.
$ship_to_countries = '';
@@ -215,8 +237,8 @@ function is_available( $package ) {
* @param mixed $code
* @return string
*/
- function clean($code) {
- return str_replace('-','',sanitize_title($code));
+ function clean( $code ) {
+ return str_replace( '-', '', sanitize_title( $code ) ) . ( strstr( $code, '*' ) ? '*' : '' );
}
}
View
1  readme.txt
@@ -154,6 +154,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Added sales by category report
* Feature - Multiple downloadable files per product/variation (kudos Justin Stern)
* Feature - Download expirey for variations (kudos niravmehta)
+* Feature - Added wildcard support to local delivery postcodes
* Templating - email-order-items.php change get_downloadable_file_url() to get_downloadable_file_urls() to support multiple files
* Tweak - If a PayPal prefix is changed, IPN requests break for all existing orders - fixed. new woocommerce_get_order_id_by_order_key() function added. Thanks Brent.
* Tweak - On add to cart success, redirect back.
Please sign in to comment.
Something went wrong with that request. Please try again.