How to Hide All Shipping Methods When “Free Shipping” is Active

Written by in Tips, Tutorials on June 19, 2013  |  18 Comments

how-to-hide-shipping-methods-when-free-shipping-is-active

Have you always wanted to hide all other shipping methods when “Free Shipping” is active, so it’s the only shipping choice that appears? You can do so with two simple code edits, as detailed below. In OpenCart versions 1.5.2 – 1.5.5, perform these core file modifications:

IN BOTH:

/catalog/controller/checkout/cart.php
/catalog/controller/checkout/shipping_method.php

BEFORE:

$this->session->data['shipping_methods'] = $quote_data;

ADD:

if (isset($quote_data['free'])) {
	$free_only['free'] = $quote_data['free'];
	$quote_data = $free_only;
} 

If you’re using OpenCart 1.5.0 or 1.5.1 versions, the files are instead named:

/catalog/controller/checkout/shipping.php
/catalog/controller/total/shipping.php

For 1.4.x OpenCart versions, the files are:

/catalog/controller/checkout/guest_step_2.php
/catalog/controller/checkout/shipping.php

And that’s all you need! Any other shipping method — including ones you’ve installed — will not appear when Free Shipping is active.

Tags: , ,

About the Author

Johnathan Shaw has been working with OpenCart since 2009. He is the owner of Clear Thinking web development and runs OpenCartX, the curated OpenCart extension marketplace.

View all posts by

18 Comments on "How to Hide All Shipping Methods When “Free Shipping” is Active"

  1. Aleksandr September 6, 2015 at 9:18 pm · Reply

    Hello,

    Could someone help me.
    I’m using similar method to show only one shipping method if in product activated this option.
    But now I need to show two shipping methods. So how I need to modify this code
    isset($quote_data['free'])) {
    $free_only['free'] = $quote_data['free'];
    $quote_data = $free_only;

    to get for example two methods – pickup and courier?

  2. Fabrizio July 28, 2015 at 4:51 pm · Reply

    Perfect, it works!
    Thanks a lot for the solution.

    OC ver. 1.5.6
    For cart.php: by line 774
    For shipping_method.php: by line 47

  3. Jitendra Kumar jena June 27, 2015 at 9:40 am · Reply

    OPENCART 2.0+
    Go To:-

    /catalog/controller/checkout/shipping.php
    /catalog/controller/checkout/shipping_method.php

    Find:-

    $this->session->data['shipping_methods'] = $quote_data; //shipping.php
    $this->session->data['shipping_methods'] = $method_data; //shipping_method.php

    Then Add Below Code Before This

    if (isset($quote_data['free']))

    {

    $free_only['free'] = $quote_data['free'];

    $quote_data = $free_only;

    }

    ***Note Replace “$quote_data” by “$method_data” in shipping_method.php

  4. Vitor February 21, 2015 at 10:39 am · Reply

    Hi Johnathan, can you tell us how to do it in Opencart 2.0.1.1?

    Thanks in advance

  5. Johnathan Shaw April 16, 2014 at 1:17 pm · Reply

    That’s likely something that needs to be changed in your quick checkout code. I’d try asking the developer to see if they could give you any direction on it.

  6. slewman April 16, 2014 at 7:41 am · Reply

    This was super helpful. cheers.

    I’m using a “fast checkout” mod that allows for the increase and decrease of product quantities on the checkout page itself.

    If you “+” items qty’s through to the free ship threshold, the free ship option is shown but not selected.

    Is this something that can be changed in opencart’s code or something to be looked at by the quick checkout dev?

    Thanks for all your great tips!

  7. Daniel January 6, 2014 at 9:56 am · Reply

    Thanks for the tip, it came in very useful for a client!

  8. Johnathan Shaw December 7, 2013 at 3:05 pm · Reply

    The edits are the same for 1.5.6. This post was written before it came out.

  9. Lee December 7, 2013 at 7:45 am · Reply

    Can you make a tutorials how to make only Free Shipping appear when active for opencart 1.5.6?

  10. Sophocles December 3, 2013 at 11:57 am · Reply

    Worked like a charm with the addition for pick up as well. Simple and quick. Thank you.

  11. Johnathan Shaw September 24, 2013 at 3:23 pm · Reply

    The rate format for Weight Based Shipping should be [weight:cost, weight:cost, etc.] so you should be able to show a $0.00 cost shipping for a 0 weight like this:

    0:0.00

    If that doesn’t work, you can certainly do it with my Weight-Based Shipping (www.opencartx.com/weight-based-shipping) extension, or you can restrict any method by weight using Restrict Shipping Methods (www.opencartx.com/restrict-shipping-methods).

  12. Sandra King September 23, 2013 at 10:56 pm · Reply

    Hello, I am trying to configure my company’s website so that if the weight is 0 the shipping cost is free – always, and no other shipping options are available. I tried doing this with weight based shipping, and it gave multiple shipping options for the 0 weight.

    Can you point me in the right direction? As far as I can tell I can either edit weight based shipping so that only the lowest shipping price shows or modify both free shipping and the cart and shipping methods pages.

  13. Tim August 20, 2013 at 6:11 pm · Reply

    That’s fast! Genius, that worked. Thank you very much.

  14. Johnathan Shaw August 20, 2013 at 5:56 pm · Reply

    You can try changing the code edit to this, which may work:

    if (isset($quote_data['free'])) {
        $free_only['free'] = $quote_data['free'];
        $free_only['pickup'] = $quote_data['pickup'];
        $quote_data = $free_only;
    }

  15. Tim August 20, 2013 at 5:34 pm · Reply

    Is it still possible to accept pick up from store? Like adding something to code? Thank you, gtrz

  16. Ralph July 19, 2013 at 2:25 pm · Reply

    Excellent post thank you! I was just about to buy this addon and found this page

  17. Essence July 1, 2013 at 6:03 am · Reply

    Thanks Johnathon for the timely post – which saved me a considerable amount of time and headaches on how to resolve showing other shipping methods when free method condition had been reached. To make life a little simpler at my end I have set up a little VQMOD to make the changes you outlined.

    • Theodore March 8, 2014 at 7:51 am ·

      It really deedpns on in what way it doesn’t work for you. Any error messages, anything in vqmod logs? You will need to tune it if you aren’t using the default theme.You might want to mail us a line with the link if it is online so we can check it out, but it will probably take some time.

Leave a Comment

comm comm comm