• Resolved raxoras

    (@raxoras)


    Hello,
    Just want to know if it’s possible to use ZIP code ranges like in the WooCommerce settings ?
    Something like 45000 could use 45* so we match the 2 first digit and it applies to all zip codes similar.

    Waiting to read you.
    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter raxoras

    (@raxoras)

    Didn’t have much time to wait for the reply so I did it myself.
    It appears that the plugin doesn’t natively handle wildcard format (45*) so I modified the class-location.php which contains the function get_price() to handle the situation for me.

    Looks like this just in case the author wants to add this for next updates or if someone is looking for a quick fix :

    public function get_price($post_id) {
    $zip = $this->zip_code;
    $country = $this->country_code;
    $prices = array_filter(Utils::get_prices($post_id), function ($price) use ($zip, $country) {
    if ($country !== $price['country_code'] && $price['country_code'] !== 'global') {
    return false;
    }

    foreach ($price['zip_codes'] as $entry) {
    if (strpos($entry, '*') !== false) {
    // Example : 41* becomes 41000-41999
    $prefix = rtrim($entry, '*');
    $min = intval($prefix . str_repeat("0", 5 - strlen($prefix)));
    $max = intval($prefix . str_repeat("9", 5 - strlen($prefix)));
    $zip_int = intval($zip);

    if ($zip_int >= $min && $zip_int <= $max) {
    return true;
    }
    } elseif ($entry === $zip) {
    return true;
    }
    }

    return false;
    });

    if (count($prices) > 0) {
    return array_values($prices)[0];
    }

    return false;
    }
    Plugin Author Zahabul Islam

    (@zahabul)

    Thanks, no problem.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Possible to use ZIP code ranges ?’ is closed to new replies.