Magento – use asterisk as wildcard within a postcode/zipcode in the Table Rates for Shipping Calculations

shippingtable-rates

Can I use asterisk within a postcode/zipcode in the Table Rates for Shipping Calculations in Magento?

For example:

GY1*

Would match all the postcodes that began with GY1.

If this cant be done, is there another way of achieving this?

Best Answer

No. The table rates only use a single '*' for 'any', but do not allow expressions with wild cards.

Source: Mage_Shipping_Model_Resource_Carrier_Tablerate

    // Render destination condition
    $orWhere = '(' . implode(') OR (', array(
        "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
        "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",

        // Handle asterix in dest_zip field
        "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '*'",
        "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
        "dest_country_id = '0' AND dest_region_id = :region_id AND dest_zip = '*'",
        "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",

        "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
        "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
        "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'",
    )) . ')';
    $select->where($orWhere);

You will need to rewrite this code or use a shipping extension that allows postcode ranges. I can recommend WebShopApps.