wc_get_wildcard_postcodes

Return a list of potential postcodes for wildcard searching.

Description

(string[]) wc_get_wildcard_postcodes( (string) $postcode, (string) $country = '' ); 

Returns (string[])

Parameters (2)

0. $postcode (string)
The postcode.
1. $country — Optional. (string) => ''
To format postcode for matching.

Usage

  1. if ( !function_exists( 'wc_get_wildcard_postcodes' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4. // The postcode. 
  5. $postcode = ''; 
  6.  
  7. // to format postcode for matching. 
  8. $country = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_get_wildcard_postcodes($postcode, $country); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-core-functions.php  
  1. function wc_get_wildcard_postcodes( $postcode, $country = '' ) { 
  2. $formatted_postcode = wc_format_postcode( $postcode, $country ); 
  3. $length = function_exists( 'mb_strlen' ) ? mb_strlen( $formatted_postcode ) : strlen( $formatted_postcode ); 
  4. $postcodes = array( 
  5. $postcode,  
  6. $formatted_postcode,  
  7. $formatted_postcode . '*',  
  8. ); 
  9.  
  10. for ( $i = 0; $i < $length; $i ++ ) { 
  11. $postcodes[] = ( function_exists( 'mb_substr' ) ? mb_substr( $formatted_postcode, 0, ( $i + 1 ) * -1 ) : substr( $formatted_postcode, 0, ( $i + 1 ) * -1 ) ) . '*'; 
  12.  
  13. return $postcodes;