Mccon Posted October 15, 2008 Share Posted October 15, 2008 Problem:Free Shipping to Delivery Address Specific To UK Post Codes (for ecommerce site) Does It Work: The following code seems to work for the postcodes I manually entered. It works on registered address or a delivery address (whichever is specified at the checkout stage) however... Problem- Now i dont profess to be a php coder of any sort so someone may have an answer to this problem (much appreciated if you do)- Some post codes have the same first three eg CV1 & CV11, now the code will pick up on both as CV1 and offer the free shipping option. I need to figure out how to exclude any that may be cv11 or cv12 etc. Again help much appreciated if ($check_flag == false) { $this->enabled = false; } // check to see if postal code is in list of allowed codes: } else { $free_ship_postcodes = array('CV1','CV2','CV3','CV4','CV5','CV6','CV7'); $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; Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 How many non free shipping postal codes are there? Quote Link to comment Share on other sites More sharing options...
Mccon Posted October 15, 2008 Author Share Posted October 15, 2008 How many non free shipping postal codes are there? hey cronix - thanks for taking an interest! I believe I would be looking at 15 (unless I have missed one) CV10, CV11, CV12, CV13, CV21, CV22, CV23, CV31, CV32, CV33, CV34, CV35, CV36, CV37, CV47 Appreciate your input! Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 Maybe just rewrite what you have and put all of those values in an array, then check the first 4 characters and if it finds them, its not free. Just the opposite of what you are doing.... Quote Link to comment Share on other sites More sharing options...
Mccon Posted October 15, 2008 Author Share Posted October 15, 2008 Maybe just rewrite what you have and put all of those values in an array, then check the first 4 characters and if it finds them, its not free. Just the opposite of what you are doing.... Ahh I think i may have confused the issue, those ones that are not free only relate to the specific ones that are free where the 4th number causes an issue. The rest of the world (post codes/zips etc) are on a standard rate. I didnt originate the code provided - i located it elsewhere and am trying to adapt... Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 <?php $free_ship_postcodes = array('CV1','CV2','CV3','CV4','CV5','CV6','CV7'); $customer_postcode = $order->delivery['postcode']; $check3digitcode = substr($customer_postcode, 0, 3); $valid_digits = in_array($check3digitcode, $free_ship_postcodes); //added from here down...first check against valid digits, then invalid if passed first validation $invalid_digits = true; if($valid_digits){ $non_free_postcodes = array('CV10', 'CV11', 'CV12', 'CV13', 'CV21', 'CV22', 'CV23', 'CV31', 'CV32', 'CV33', 'CV34', 'CV35', 'CV36', 'CV37', 'CV47'); $check4digitcode = substr($non_free_postcodes, 0, 4); $invalid_digits = in_array($check4digitcode, $non_free_postcodes); } if ($valid_digits && $invalid_digits) $this->enabled = true; Might not be the best, but should do what you want. Quote Link to comment Share on other sites More sharing options...
Mccon Posted October 15, 2008 Author Share Posted October 15, 2008 Legend - im actually heading off now but will drop back online tomorrow after testing and let you know! many thanks for your help & input ! Quote Link to comment Share on other sites More sharing options...
Mccon Posted October 15, 2008 Author Share Posted October 15, 2008 hiya - just had a quick try .. seems to be making a charge against the cv1 now and the cv11.. how you guys understand this code astounds me! I struggle enough with english.... Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 15, 2008 Share Posted October 15, 2008 This works... <?php $free_ship_postcodes = array('CV1','CV2','CV3','CV4','CV5','CV6','CV7'); $customer_postcode = $order->delivery['postcode']; $check3digitcode = substr($customer_postcode, 0, 3); $valid_digits = in_array($check3digitcode, $free_ship_postcodes); //added from here down...first check against valid digits, then invalid if passed first validation $invalid_digits = false; if($valid_digits){ $non_free_postcodes = array('CV10', 'CV11', 'CV12', 'CV13', 'CV21', 'CV22', 'CV23', 'CV31', 'CV32', 'CV33', 'CV34', 'CV35', 'CV36', 'CV37', 'CV47'); $check4digitcode = substr($customer_postcode, 0, 4); $invalid_digits = in_array($check4digitcode, $non_free_postcodes); } if ($valid_digits && !$invalid_digits) $this->enabled = true; Quote Link to comment Share on other sites More sharing options...
Barand Posted October 15, 2008 Share Posted October 15, 2008 in your original code, replace $check3digitcode = substr($customer_postcode, 0, 3); with $check3digitcode = trim(substr($customer_postcode, 0, strlen($customer_postcode)-3)); to get the first part of the post code (3 or 4 chars) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.