List of Postcodes/Zipcodes

codebrighton's picture
Offline
Joined: 02/18/2010
Juice: 9
List of Postcodes/Zipcodes

Hi I needed this functionality and had to edit uc_order/uc_order.ca.inc (also fixed an issue with postcodes in that they could be in upper or lower case!)

Old code:

function uc_order_condition_delivery_postal_code($order, $settings) {
  // Trim the wildcard off the pattern.
  $pattern = rtrim($settings['pattern'], '*');

  // Return TRUE if the delivery postal code begins with the pattern.
  return strpos($order->delivery_postal_code, $pattern) === 0;
}

My new code:

function uc_order_condition_delivery_postal_code($order, $settings) {
    $found = FALSE;
    $p_array = explode(',', $settings['pattern']);
    foreach ($p_array as $p) {
        // Trim the wildcard off the pattern (don't really need the * anyway!)
        $pattern = rtrim($p, '*');
        if(strpos(strtolower($order->delivery_postal_code), strtolower($pattern)) === 0) {
            $found = TRUE;
        }
    }
    // Return TRUE if the delivery postal code begins with the pattern.
    return $found;
}

Code probably could be a bit more efficient, but hope this helps someone

Postal Code conditions: Tame wildcards By: KingAndy (16 replies) Thu, 04/09/2009 - 08:11