Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Free shipping to a single postal code

Free shipping to a single postal code

Views: 1,293

Results 1 to 7 of 7
23 May 2011, 7:37 PM
#1
angelica avatar

angelica

New Zenner

Join Date:
Feb 2011
Posts:
23
Plugin Contributions:
0

Free shipping to a single postal code

I've been searching online for some help with this and found that **DrByte **has a code that you can put in freeshipper.php; however, it seems that it only works for various regions with a postal code that begins in letters [BD1]. The original code is below, and the second code is the one that I have modified for what I am looking for. But the modified version is not working and I don't know what is wrong with it or what I am doing wrong.

        if ($check_flag == false) {
          $this->enabled = false;
        }

      // check to see if postal code is in list of allowed codes:
      } else {
        $free_ship_postcodes = array('L1S','L1T','L1V','L1W','L1X','L1Y','L1Z','L3P','L3R','L3S','L3T','L4A','L4B','L4C','L4E','L4H','L4J','L4K','L4L','L4S','L4T','L4V','L4W','L4X','L4Y','L4Z','L5A','L5B','L5C','L5E','L5G','L5H','L5J','L5K','L5L','L5M','L5N','L5P','L5R','L5S','L5T','L5V','L5W','L6A','L6B','L6C','L6E','L6G','L6P','L6R','L6S','L6T','L6V','L6W','L6X','L6Y','L6Z','L7A','M1B','M1C','M1E','M1G','M1H','M1J','M1K','M1L','M1M','M1N','M1P','M1R','M1S','M1T','M1V','M1W','M1X','M2H','M2J','M2K','M2L','M2M','M2N','M2P','M2R','M3A','M3B','M3C','M3H','M3J','M3K','M3L','M3M','M4A','M4B','M4C','M4E','M4G','M4H','M4J','M4K','M4L','M4M','M4N','M4P','M4R','M4S','M4T','M4V','M4X','M4Y','M5A','M5B','M5C','M5E','M5G','M5H','M5J','M5K','M5L','M5M','M5N','M5P','M5R','M5S','M5T','M5V','M5W','M5X','M6A','M6B','M6C','M6E','M6G','M6H','M6J','M6K','M6L','M6M','M6N','M6P','M6R','M6S','M7A','M7Y','M8V','M8W','M8X','M8Y','M8Z','M9A','M9B','M9C','M9L','M9M','M9N','M9P','M9R','M9V','M9W');
        $customer_postcode = $order->delivery['postcode'];
        $check3digitcode = substr($customer_postcode, 0, 3);
        $valid_digits = in_array($check3digitcode, $free_ship_postcodes);
        if ($valid_digits) $this->enabled = true;
      }
    }

It was meant to do free shipping in a Canadian area.

	// check to see if postal code is in list of allowed codes:
      } else {
        $free_ship_postcodes = array('84601');
        $customer_postcode = $order->delivery['postcode'];
        $check4digitcode = substr($customer_postcode, 0, 4);
        $valid_digits = in_array($check4digitcode, $free_ship_postcodes);
        if ($valid_digits) $this->enabled = true;

From what I can tell, the code is not reading for letters or numbers, just to match characters, but even with the simple change it is not working. I have also tried adding a space to the end of the array and making the substring match to the 5th space...I don't know if that makes any kind of difference. I have also tried removing the array as I only have one postal code to match.

It seems that other people have tried modifying the code for an all numeral postal code with more digits than it was originally intended for, but none of them have been able to get it to work either. I'd appreciate any insight on the above code.

23 May 2011, 11:22 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping to a single postal code

What are you trying to do?

You give a 5 digit zip code: 84601

But you are trying to squeeze that into 4 digits ... :blink:

23 May 2011, 11:59 PM
#3
angelica avatar

angelica

New Zenner

Join Date:
Feb 2011
Posts:
23
Plugin Contributions:
0

Re: Free shipping to a single postal code

Oh, well I tried it with 5 places as well, but that didn't work either. But for an explanation, I was thinking the count started with 0 so it would be 0, 1, 2, 3, 4 rather than 1, 2, 3, 4, 5.

24 May 2011, 12:00 AM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping to a single postal code

If I use 0, 5 with that Zip Code, I see the Free Shipping ...

24 May 2011, 12:05 AM
#5
angelica avatar

angelica

New Zenner

Join Date:
Feb 2011
Posts:
23
Plugin Contributions:
0

Re: Free shipping to a single postal code

hmm... do you think it makes a difference that my products are being bought by someone who ships it to someone else? So there are two differing postal codes, the customers and the shipment? I wouldn't think so, but I honestly don't know why the code isn't working for me. :(

24 May 2011, 12:19 AM
#6
angelica avatar

angelica

New Zenner

Join Date:
Feb 2011
Posts:
23
Plugin Contributions:
0

Re: Free shipping to a single postal code

I take it back! It works just fine now. I forgot that I removed the array but then I didn't change the call on the array. :oops: But thank you very very much for correcting the 4 and 5. Between a few things, I wouldn't have been able to actually work it out. I'm still working on learning more about php and everything else for that matter.

24 May 2011, 12:38 AM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free shipping to a single postal code

You are most welcome thanks for the update that this is working for you ... :smile: