Search code examples
prestashop

Prestashop shipping cost by state


Is there by any chance a way to set shipping cost by state in a carrier in prestashop?

i.e. let's say i want a different shipping cost to send in Alabama than in Alaska with the same carrier

Thanks


Solution

  • There are a couple ways of doing this. You can purchase an external module, such as this one, or create an override like so:

    1) Copy "classes/Address.php" to "override/classes/Address.php".

    2) In line 28 change class name from AddressCore to Address

    3) Before function getZoneById, paste this new function

    /**
    * Return postcode of address
    *
    * @param $id_address Address id
    * @return integer postcode
    */
    public static function getPostcodeByAddress($id_address){
        $row = Db::getInstance()->getRow('
        SELECT `postcode`
        FROM '._DB_PREFIX_.'address a
        WHERE a.`id_address` = '.(int)($id_address));
        return $row['postcode'];
    }
    

    4) Add before first line of function getZoneById this:

    $postcode=self::getPostcodeByAddress($id_address); 
    
    if(in_array($postcode,array(your list of postcodes))){
        return id-of-your-zone;
    }