Shipping Weight Ranges

All of our physical products will be within one category. I need to set-up weight-based shipping rates which are only available to customers in mainland UK. If the total weight of their order is less than 6, they pay £7.99, then if less than 12 they pay £4.99, and if 12 or over it's free, What would be the easiest way to achieve this in Foxycart? Also, it would be useful if there was a way of preventing customers with non-mainland UK postcodes from ordering. We need to offer 'collection' as an option as well.
Comments
  • fc_adamfc_adam FoxyCart Team
    edited April 2016
    @grahamlinter,

    Sure thing! In 2.0, you can get pretty close with your location restriction by using our location whitelisting/blacklisting. You'll find that option within your store's configuration section - under cart it's "Customize whitelist/blacklist filtering of countries and regions". You can whitelist to just the UK - and that will be the only option available.

    To restrict to the mainland UK - that will require some custom javascript. You'd need to hook onto the postal code field and whenever it changes, check if it's a valid postal code range. If you'd like a hand with getting started on that, if you can let us know what the range(s) would be, we can show you what that might look like.

    For the shipping options, you would need the custom flat rate snippet as detailed here: https://wiki.foxycart.com/v/2.0/snippets/flat_rate_shipping_modification. Example 2 will give you an idea of the custom logic you could have for working with the weight.
  • grahamlintergrahamlinter Member
    edited April 2016
    Thanks for this help,
    We would need to check against an array of non-mainland postcode prefixes which would include the Channel Islands ('GY' and 'JE'). If you could provide a sample script that would just disallow 'GY' and 'JE' prefixed postcodes which I could then build on then that would be much appreciated.
  • fc_adamfc_adam FoxyCart Team
    @grahamlinter,

    If it's just removing certain prefixes from being valid, there is a different way you could approach this. With our postal code lookup functionality, we include some checks on the formatting for what makes a valid postal code for a given country. You could edit that to remove the prefixes you don't want like this:
    <script>FC.client.on("ready.done", function() {
    FC.json.config.locations.GB.pc.regex = "GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}";
    });</script>
    That is the regular expression as it is by default. Removing "GY" and "JE" would look like this:
    <script>FC.client.on("ready.done", function() {
    FC.json.config.locations.GB.pc.regex = "GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}";
    });</script>
    From there I removed JE| and GY|. If someone then tries to enter a postal code beginning with either of those it won't recognise it. You can paste that code into the footer option of the "Add custom header and footer code to your templates" configuration option for your store.
  • Thanks Adam,
    That all makes sense but where do I need to go to in FoxyCart to insert that script?
  • fc_jedfc_jed FoxyCart Team
    @grahamlinter

    You can insert that script in your store's custom footer (Configuration > check Add custom header and footer code to your templates)
  • Thanks Jed,
    I have UK delivery functionality working fine. To achieve that I have used the custom flat rate snippet in the custom footer header and footer,, I have enabled "Customize whitelist/blacklist filtering of countries and regions", set the filter usage to 'Shipping locations only' and set the filter type to 'whitelist'. I have some custom shipping code in the custom footer to control when the price of shipping depending on the total weight, but wherever I try and insert the postcode definitions script you provided in your answer, either the shipping stops working altogether or there is no effect. Where exactly should I be inserting that code?
  • fc_adamfc_adam FoxyCart Team
    @grahamlinter,

    The code I provided above can just be added to the "custom footer" option on your store's configuration page as Jed noted. If the store isn't live - if you could add it and link us to your store so we could take a look - that would be great.
  • fc_adamfc_adam FoxyCart Team
    @grahamlinter,

    Thanks for whispering that link - I was able to replicate what you were seeing. The issue was my mistake sorry, the code needs to be altered slightly to work in Sidecart as well. Give this a try instead of what you copied in previously:
    <script>{% if cart_is_fullpage or context == 'checkout' %}
    FC.client.on("ready.done", function() { updateRegex(); });
    {% else %}
    updateRegex();
    {% endif %}
    function updateRegex() {
    FC.json.config.locations.GB.pc.regex = "GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}";
    }</script>
  • My custom footer now has that script right at the top but a Guernsey postcode, e.g. GY1 3XZ, still allows UK shipping. Any ideas?
  • fc_adamfc_adam FoxyCart Team
    @grahamlinter,

    You may have still had a cached version of the previous set up. I just tested and your Sidecart doesn't allow that postal code.
  • You're right and I can confirm it's working a treat now! Thanks so much for all your help.
  • fc_adamfc_adam FoxyCart Team
    Awesome! Happy to help.
Sign In or Register to comment.