Visser Labs

Sunday, November 8, 2009

Flat Rate Shipping for Australian States and Country Regions

flatrate-polaMy delving into Instinct’s WP E-Commerce plugin for WordPress has raised a few questions and now that I have had some spare time I’ve prepared some Visser-style hacks and solutions!

I recently raised in Hot Aussie Topics for WP E-Commerce that there was no shipping calculator supporting flat-rate shipping for Australian states which were manageable within the WordPress Administration and selectable by customers at checkout, well here’s my fix.

  • Login to WordPress Adminstrator
  • Under General Settings set the Base Country/Region to Australia and save changes
  • Using your favourite FTP manager navigate to /wp-content/plugins/wp-e-commerce/shipping/... and with your preferred text editor open flatrate.php
  • Ensure you have an original copy of flatrate.php stored on your computer.
  • On line #39 paste the following…
    case 'AU':
    $output .= "<tr class='rate_row'><td>Australian Capital Territory</td><td>$<input type='text' size='4' name='shipping[au-act]' value='{$shipping['au-act']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>New South Wales</td><td>$<input type='text' size='4' name='shipping[au-nsw]' value='{$shipping['au-nsw']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>Northern Territory</td><td>$<input type='text' size='4' name='shipping[au-nt]' value='{$shipping['au-nt']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>Queensland</td><td>$<input type='text' size='4' name='shipping[au-qld]' value='{$shipping['au-qld']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>South Australia</td><td>$<input type='text' size='4' name='shipping[au-sa]' value='{$shipping['au-sa']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>Tasmania</td><td>$<input type='text' size='4' name='shipping[au-tas]' value='{$shipping['au-tas']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>Victoria</td><td>$<input type='text' size='4' name='shipping[au-vic]' value='{$shipping['au-vic']}'></td></tr>";
    $output .= "<tr class='rate_row'><td>Western Australia</td><td>$<input type='text' size='4' name='shipping[au-wa]' value='{$shipping['au-wa']}'></td></tr>";
    break;
  • On what was line #54 replace the following with my updated version:
    Original: if (get_option('base_country')=='NZ') {
    Updated: if (get_option('base_country')=='NZ' || get_option('base_country') == 'AU') {
  • On what was line #92 add in the following between the NZ and US ‘case’ entries:
    case 'AU':
    $shipping_quotes["Australian Capital Territory"] = (float)$flatrates['au-act'];
    $shipping_quotes["New South Wales"] = (float)$flatrates['au-nsw'];
    $shipping_quotes["Northern Territory"] = (float)$flatrates['au-nt'];
    $shipping_quotes["Queensland"] = (float)$flatrates['au-qld'];
    $shipping_quotes["South Australia"] = (float)$flatrates['au-sa'];
    $shipping_quotes["Tasmania"] = (float)$flatrates['au-tas'];
    $shipping_quotes["Victoria"] = (float)$flatrates['au-vic'];
    $shipping_quotes["Western Australia"] = (float)$flatrates['au-wa'];
    break;
  • Save changes and upload the updated flatrate.php to your web server.
  • Within WordPress Administrator open General Settings and switch to the Shipping tab
  • Select Flat Rate under Internal Shipping Calculators and save changes
  • Hover over the Flat Rate checkbox and click on Edit
  • Under Flat Rate in the right column of the Shipping tab fill in your fixed rate pricing for each Australian state
  • Click Update to save changes

That’s it, you’ve just hooked up flat rate pricing for Australian customers! Now jump on the front-end and test to ensure that when Australia is set from the drop-down that your prices are coming up. We’re all learning here so if there’s any problems let me know in the comments or send me an e-mail for personal assistance.

11 Comments »

  1. Mark Williams
    December 21

    Gday mate – quick question from a n00b – we build simple WP sites for small business in Australia and we’re looking to add an ecom string to our bow. This looks good what you’ve done here – can I ask: would this mean if Instinct release a new update, we’d have to then go back and recopy in this hack?

    ps – we build all our WP sites using Thesis – which seems to cut the dev time down quite considerably – I dunno if you’ve had any experience with that or not.

    Cheers mate, Mark ;)

  2. December 21

    Hey Mark, you’re spot on. Each time you upgrade a client’s WP E-Commerce you’ll need to bring across the hack/changes.

    Assuming you’ve got a file/folder comparison application you can merge the changes between your existing code and the latest release of WP E-Commerce. I use Beyond Compare 3.

  3. Mark Williams
    December 21

    Ok Michael no worries – and thanks for the heads up with Beyond Compare 3 – I’ll give it a shot ;)

  4. March 24

    please give me one flatrate.php ?
    ths!

  5. March 24

    Hi veker, unforunately that’s difficult as my version may not match your own. I provided step by step instructions to allow store owners to customise their flatrate.php

  6. Stephen N
    March 26

    Great post, thanks. I’m doing this for canada and adding the provinces. They show up in the admin and I’m adding the flat rate shipping but when I calculate the shipping rates from the front end they do not come up. I was wondering if I have the country codes right example ca-bc. Where did you find the codes that wp-ecomcerce is using for its variables? Could this be something else?

  7. March 26

    Hi Stephen, I’m pretty sure that the state/country codes are stored in one of the wp_wpsc… tables, there’s a country codes table.

  8. March 26

    Hey its working, I was too tired and missed editing the $shipping_quotes. I’m more of designer and I got this working in 30min. Thanks for the tips.

  9. March 28

    Thanks, I came across one oddity, when I calculate the shipping from the drop down in the check out it always goes to the first province. The list appears when the province is selected it calculates the proper shipping.

  10. Sgc
    May 20

    Hi, My client wishes to offer Express Post as an option along with standard post. For eg based on weight i.e. products upto 500g will cost 10$ standard and 13$ Express, whereas products upto 3 Kg will cost 15$ standard and 22$Express. How can I implement this feature?

  11. Hey Sgc, best contacting a WordPress expert with experience building shipping modules – which I am unfortunately not – from the Get Shopped (http://www.getshopped.org) website under Resources > WP Consultants page.

Leave a comment

The perfect comment is interesting, on-topic and/or highly amusing.