Pages

Friday 29 November 2013

Simple Opencart tutorial - shipping rate based on percentage of order

I was looking all over the internet for a free module to allow me set the shipping cost by a percentage if the order total was within a certain range; but to no avail :(
So I decided to do it myself.

Here's what I needed...

So for example:
  • If we set the shipping cost to be 10% of the order total, for an order total of £158.00, the shipping cost will be £15.80.
This is how I did it:

First of all,
  1. You have to download this free module -> Total Based Shipping (http://www.opencart.com/index.php?route=extension/extension/info&extension_id=4029 )
  2. Follow the instructions on how to install the module (it's really easy)
  3. When you are done with that, navigate to catalog\model\shipping\standard_cost.php
    • NB: the standard_cost.php file will be a file from the module you just downloaded.
  4. Scroll to where you see, it should be around line 38 - 50
    • if ($cart_subtotal <= $data[0]) {
      if (isset($data[1])) {
      $cost = $data[1];}
      break;
      }
  5. Then insert this
    • elseif ($cart_subtotal <= 200.00 ){
      $cost = $cart_subtotal*0.1;
      break; }

Simple! You just needed to add 3 lines of code.

The Module you downloaded in step 1 allows you to set specific shipping cost based on the order total. So we just included that code to calculate shipping cost based on a set percentage (in the above example, it's 10%. To calculate for a different percentage, just change the '0.1' in the code to whatever you want).

This was a quick fix and unfortunately, it's hard-coded. I'll try and improve on it so it can be modified from Opencart's back-end and update this post.

Please feel free to make suggestions or comments below. Thanks

    6 comments:

    1. Jimmy, provided me with services to ship all my belongings from New York to his store. He offered to even deliver my belongings 12 large boxes to my apartment in the Sunset district. www.viabox.com

      ReplyDelete
    2. Any chance you could tell me how to change this Module so that if I put my rates in the GST tab, I can actually have it say something other than GST? like Shipping??

      ReplyDelete
      Replies
      1. Hey Taleen, sorry for the late reply. Apologies, but I can't help with that unfortunately :(

        Delete
    3. That is a really good tip especially to those fresh to the blogosphere. Short but very precise information… Thanks for sharing this one. A must read article!

      ReplyDelete
    4. Hi there, I enjoy reading all of your article post. I wanted to write a little comment to support you.

      ReplyDelete
    5. I'm curious to find out what blog system you are working with? I'm experiencing some minor security issues with my latest website and I would like to find something more safe. Do you have any suggestions?

      ReplyDelete