Magento Onestep Checkout – Remove Shipping Method Step

In this blog, we will see how to remove the shipping method step from magento onepage checkout

The source code of this module has been tested in magento 1.6 version but should work fine 1.4+.
Removing the shipping method step is pretty simple, here are the steps to do it. I am going to set the ‘freeshipping’ shipping method as the default shipping method so that the checkout process goes smoothly. Also for this code to work make sure the freeshipping method is enabled from admin. Attached is the source code for this module
[dm]10[/dm]

Step1: Onepage Block

First we need to override the Onepage.php block, so that we can change the steps array. So to override the block Mage_Checkout_Block_Onepage open your module’s config.xml file and put inside the blocks tag, below code

 <checkout>
	    		<rewrite>
	    			<onepage>Excellence_Remove_Block_Onepage</onepage>
	    		</rewrite>
	    	</checkout>

So the core block Mage_Checkout_Block_Onepage has been overridden by Excellence_Remove_Block_Onepage block. In the code in this block is

<?php
class Excellence_Remove_Block_Onepage extends Mage_Checkout_Block_Onepage
{
	public function getSteps()
	{
		$steps = array();

		if (!$this->isCustomerLoggedIn()) {
			$steps['login'] = $this->getCheckout()->getStepData('login');
		}

		$stepCodes = array('billing', 'shipping', 'payment', 'review');

		foreach ($stepCodes as $step) {
			$steps[$step] = $this->getCheckout()->getStepData($step);
		}
		return $steps;
	}
}

Here i have simple removed the ‘shipping_methods’ step.

Step2: pHTML and Javscript

Here we need to include our custom javascript file for the checkout, since we will make changes to the onepage.phtml file. We will include the javascript file in onepage.phtml. Using the layout file, we will override the default phtml file to our modules phtml file.

<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/removecheckout.js') ?>"></script>

and also change the javsacript code

var checkout = new Checkout(accordion,{

to

var checkout = new Excellence(accordion,{

Next we need to create the Excellence javascript class in the removecheckout.js

var Excellence = Class.create(Checkout, {
	initialize: function($super,accordion, urls){
		$super(accordion, urls);
		//New Code Addded
		this.steps = ['login','billing', 'shipping', 'payment', 'review'];
	}
});

The full source code for doing the above is found in the module files.

Step3: Onepage Controller

The default OnepageController.php is override so that we can change to functions. The saveBillingAction() and saveShippingAction(). The source code is given below

public function saveBillingAction()
	{
		if ($this->_expireAjax()) {
			return;
		}
		if ($this->getRequest()->isPost()) {
			//            $postData = $this->getRequest()->getPost('billing', array());
			//            $data = $this->_filterPostData($postData);
			$data = $this->getRequest()->getPost('billing', array());
			$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);

			if (isset($data['email'])) {
				$data['email'] = trim($data['email']);
			}
			$result = $this->getOnepage()->saveBilling($data, $customerAddressId);

			if (!isset($result['error'])) {

				$method = 'freeshipping_freeshipping';
				$result = $this->getOnepage()->saveShippingMethod($method);

				if (!isset($result['error'])) {

					if ($this->getOnepage()->getQuote()->isVirtual()) {
						$result['goto_section'] = 'payment';
						$result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
						);
					} elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
						$result['goto_section'] = 'payment';
						$result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
						);

						$result['allow_sections'] = array('shipping');
						$result['duplicateBillingInfo'] = 'true';
					} else {
						$result['goto_section'] = 'shipping';
					}
				}
			}

			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
		}
	}

	public function saveShippingAction()
	{
		if ($this->_expireAjax()) {
			return;
		}
		if ($this->getRequest()->isPost()) {
			$data = $this->getRequest()->getPost('shipping', array());
			$customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
			$result = $this->getOnepage()->saveShipping($data, $customerAddressId);

			if (!isset($result['error'])) {
				$method = 'freeshipping_freeshipping';
				$result = $this->getOnepage()->saveShippingMethod($method);

				if (!isset($result['error'])) {

					$result['goto_section'] = 'payment';
					$result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
					);
				}
			}
			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
		}
	}

The main code to look at is

$method = 'freeshipping_freeshipping';
				$result = $this->getOnepage()->saveShippingMethod($method);

Here we are setting the freeshipping method as the default method. If you want to set some other shipping method as the default, you need to put that methods code here. Also code to notice is

$result['goto_section'] = 'payment';
					$result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
					);

This code sets the next step after billing and shipping to be payment, and pass the html of the payment method.

This is all that is required to remove the shipping step. Detailed source code is there in the module attached with the blog.
  • Claude

    Hi,
    Wonder how to adapt yr code to cope with a sweet tooth extension. Sidebar and javascript  modified.
    Any idea ?
    Thks for all
    Claude 

    • Manish Prakash

      Not sure what you mean by sidebar and javascript modified?

      If by sidebar you mean the progress side, then just make the code changes i have mentioned in the sweet tooths progress file.  same for the javascript

  • Hi,

    Wonder how to cope with a Sweet tooth rewards extension. Any idea to adapt code ?
    Thanks for all
    Claude

    • Manish Prakash

      No, i havn’t used this extension before. Where exactly is the Sweet tooth extension conflicting with the removal shipping method? if you could explain maybe i can help.

      • As explain in my last comment, the problem was not a conflict between Sweet tooth and yr code but the disposition of the “Skin” folder in yr Zip.
        For info: to integrate with Sweet tooth, you have to manually add this piece of code into the progress.phtml file
        getModuleConfig(‘TBT_Rewards’)->is(‘active’, ‘true’)) : ?> toHtml(); ?>

        This adds the sweet tooth correct sidebox.

        That’s all
        Best regards
        Claude

        • Manish Prakash

          Yes thanks again for your help

  • Hi,

    Forget my first comment. Everything working smoothly now.

    The problem aose from a wrong disposition into your Zip file. “Skin” is under “App”, should be at same level. Otherwise, the script removecheckout.js cannot be found.

    Thks again
    Claude

    • Manish Prakash

      Ok great. Thanks for pointing it out the problem i will fix it

  • Hi,
    when i use your code i got “Please specify a shipping method” javascript popup at the final page when i check “place order” button. i did the debug the code and i found appcodecoreMageSalesModelServiceQuote.php in line number 301 $method= $address->getShippingMethod(); not return ‘freeshipping_freeshipping’ it’s retun null could you help me to fix this ?

    • Sven Daems1

      Hi,
      In onepagecontroller.php – saveBillingAction add: $this->saveShippingMethodAction();
      after line 36:
      elseif (isset($data[‘use_for_shipping’]) && $data[‘use_for_shipping’] == 1) {
      $this->saveShippingMethodAction();

      and after line 70:
      if (!isset($result[‘error’])) {
      $this->saveShippingMethodAction();

      and add function:
          public function saveShippingMethodAction()
          {
              $this->_expireAjax();
              if ($this->getRequest()->isPost()) {
                  $this->savePaymentAction();
                  $data = $this->getRequest()->getPost(‘shipping_method’, ‘freeshipping_freeshipping’);
                  $result = $this->getOnepage()->saveShippingMethod($data);
                     $this->getResponse()->setBody(Zend_Json::encode($result));
              }

          }

      grtz
                             

  • FYI I’m using magento 1.6.1 CE

  • duzenz

    is there any way for onepage checkout remove shipping_information step? this is working rightly but i cannot remove shipping info step.

    • Manish Prakash

      Yes it is possible, i will write blog on these topics soon. Won’t be possible to explain in this comment

  • finally found the solution I will post hear if any one has problems.
    use this line of code
    Mage::getSingleton(’checkout/type_onepage’)->getQuote()->getShippingAddress()-> setShippingMethod($method)->save();

    after
    $result = $this->getOnepage()->saveShippingMethod($method);

    • Rohanpatil

      Hi Isuru Ratnayake

      I Tried it but not works can you please explain in which file and where need to put this 1 line code

      Thanks

      • Manish Prakash

        Is your freeshipping method enabled in admin for all order total?

  • Adam Shuy

    I used your code then add free blog of  the aheadworks.com.  Then the onepage theme is gone.  It turns to a plain html without any css modification.

    Do you have any idea what causes it?

    • Manish Prakash

      can you send me URL of your website?

  • Rohanpatil

    Hi

    This is very nice you made my work easy but i also want to hide the billing and shipping steps using the same module can you give the right direction for this to me

    thanks in advance

  • Nguyendeicide

    Add this code on line 25 and 65 one OnePageController.php:
    Mage::getSingleton(‘checkout/type_onepage’)->getQuote()->getShippingAddress()-> setShippingMethod($method)->save();
    and enable shipping method.
    It’s working on 1.4, but I can’t disable this module (blank on onepage checkout after disabled.)

    • Manish Prakash

      How are you disabling the module?

      •  This was super helpful. Thank you so much : )

  • doug haber

    Hi there!

    I uploaded the files from the archive, but shipping is all still present?

    • Manish Prakash

      Which magento version are you using?

      The module works for other people? Are you sure you have installed it properly?

  • This seems to work quite well if the user selects “ship to this address” in the billing section.  However, if someone specifies “ship to different address” we get a js prompt that says “invalid shipping method”.

    Interestingly enough, if select “ship to this address”, then go back to the billing section and switch to “ship to different address”, all works correctly.

    • adg

      Were you able to find a fix for that, as it is a game changer for this nice piece of work. As they say, horseshoes and hand grenades.

    • adg

      Ah, it’s in “onepagecontroller.php”. Need to change the 2nd $method near the bottom to the one you’re using and that’s valid for the sale.

      • Manish Prakash

        Sorry guys i was busy so couldn’t reply to your comments.

        This issue is fixed now.

        This is the updated to put in file Excellence_Remove_OnepageController in the saveBillingAction function.

        if($data[‘user_for_shipping’] != 0){ $method = ‘freeshipping_freeshipping’; $result = $this->getOnepage()->saveShippingMethod($method);}

        need to add this if condition

        • This module works great I just installed onto a 1.6.1.0 site I have setup for developing and testing. The only issue I ran into was an error on this line you added to fix a previous bug. I believe it should be …$data[‘use_for_shipping’]… instead of …$data[‘user_for_shipping’]… I made this change and it all worked great.

          Thanks!

    • Manish Prakash

      Sorry guys i was busy so couldn’t reply to your comments.

      This issue is fixed now.

      This is the updated to put in file Excellence_Remove_OnepageController in the saveBillingAction function.

      if($data[‘user_for_shipping’] != 0){ $method = ‘freeshipping_freeshipping’; $result = $this->getOnepage()->saveShippingMethod($method);}

      need to add this if condition

      • aazi

        hi
        when i check out as an new registered user this error is comes “invalid shipping method”
        I add this if condition but it again show me “invalid shipping method” error message i am using 1.7 magento version can tell me why its come again .

  • adg

    I keep getting, “Invalid Shipping Method”. I use table rate, however. But I’ve enabled “Free Shipping” and changed “freeshipping_freeshipping” to “tablerate_tablerate” in onepagecontroller.php. Using Mag 1.6

  • adg

    Oops. It’s, “tablerate_bestway”, not “tablerate_tablerate” for $method. Anyway, it all worked fine…until I tried to ship to a different address, then it broke. “Invalid Shipping Method” is what was returned. Has anyone resolved this?

  • adg

    Works great. I would mention the second “$method” string in onepagecontrollers.php. If that isn’t set properly and if customer chooses “ship to different address”, the JS will return an error.

  • Sven Daems1

    Hi,
    I installed your module and everything seems to work fine except for one thing. When I try to place the order, a message shows up telling me I didn’t set a shipping method. Any idea where it went wrong? Thx

  • Pingback: Magento One Page Checkout | Magento Media()

  • ceckoslab

    @manishiitg:disqus Thanks for the code.

    I adopted it under Magento CE 1.6.2.0 and had an issue:

     – It skipped the shipping method step, but on the review step ( last step before the order is placed )
    the shipping wasn’t included in the totals.
     – When I pressed the button “Place order” I got next error message: “Please specify a shipping method.”

    To resolve this issue I added in Excellence_Remove_OnepageController in
     saveBillingAction and saveShippingAction next line of code:

    $this->getOnepage()->getQuote()->collectTotals()->save();

    before:

    $this->getResponse()->setBody(Mage::helper(‘core’)->jsonEncode($result));

    so methods now looks like:

    public function saveBillingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { //            $postData = $this->getRequest()->getPost(‘billing’, array()); //            $data = $this->_filterPostData($postData); $data = $this->getRequest()->getPost(‘billing’, array()); $customerAddressId = $this->getRequest()->getPost(‘billing_address_id’, false); if (isset($data[’email’])) { $data[’email’] = trim($data[’email’]); } $result = $this->getOnepage()->saveBilling($data, $customerAddressId); if (!isset($result[‘error’])) { if($data[‘use_for_shipping’] != 0){                    $method = ‘freeshipping_freeshipping’;                    $result = $this->getOnepage()->saveShippingMethod($method); } if (!isset($result[‘error’])) { if ($this->getOnepage()->getQuote()->isVirtual()) { $result[‘goto_section’] = ‘payment’; $result[‘update_section’] = array(                        ‘name’ => ‘payment-method’,                        ‘html’ => $this->_getPaymentMethodsHtml() ); } elseif (isset($data[‘use_for_shipping’]) && $data[‘use_for_shipping’] == 1) { $result[‘goto_section’] = ‘payment’; $result[‘update_section’] = array(                        ‘name’ => ‘payment-method’,                        ‘html’ => $this->_getPaymentMethodsHtml() ); $result[‘allow_sections’] = array(‘shipping’); $result[‘duplicateBillingInfo’] = ‘true’; } else { $result[‘goto_section’] = ‘shipping’; } } }            $this->getOnepage()->getQuote()->collectTotals()->save(); $this->getResponse()->setBody(Mage::helper(‘core’)->jsonEncode($result)); } }

    public function saveShippingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(‘shipping’, array()); $customerAddressId = $this->getRequest()->getPost(‘shipping_address_id’, false); $result = $this->getOnepage()->saveShipping($data, $customerAddressId); if (!isset($result[‘error’])) { $method = ‘freeshipping_freeshipping’; $result = $this->getOnepage()->saveShippingMethod($method); if (!isset($result[‘error’])) { $result[‘goto_section’] = ‘payment’; $result[‘update_section’] = array(                        ‘name’ => ‘payment-method’,                        ‘html’ => $this->_getPaymentMethodsHtml() ); } }            $this->getOnepage()->getQuote()->collectTotals()->save(); $this->getResponse()->setBody(Mage::helper(‘core’)->jsonEncode($result)); } }

    Thanks again! This saved some money and time!
    I believe, that my suggestion will help to somebody who has the same problem.

    • Thanks Dude!
      You save my time 🙂

    • juliencuenin

      Sadly this didn’t work in Magento 1.8, any idea why?

    • Chirag Dodia

      @ceckoslab:disqus Thanks a lot. You saved my time.

  • how can i dwnload the zip.. m logged in via facebook..

  • Hello, enable free shipping method from admin area

  • Does your download include all mods detailed in your comments? Also, Has this been used with a free shipping if purchase is over a $ amount?
    Thanks for your time…
    Bill

  • ceckoslab

    Cool 🙂 Sorry for the bad formatted code, but I couldn’t do it better. Good luck.

  • Muhammad Ibrahim

    Does not work for me..

  • It doesnot work at all on magento 1.7.2….

  • Gavin

    I’m trying to download the file, but there doesn’t seem to be any download link after i’ve signed in with facebook? Thanks

  • jainmca4444

    jhhj

  • HI
    thanks for this code but my need is different ..
    im using magento1.7.2 ,i will only use downloadable product so there is no need to fill address for customer.can i remove billing as well as shipping step? is this possible? How?

  • The shipping doesn’t seem to disappear in 1.7.0.2. I had to add this part to get it removed from the progress bar which I am sure isn’t good coding: in progress.phtml getCheckout()->getStepData(‘shipping’, ‘is_show’) && false): ?> line 22. It then gets removed and it is skipping the shipping step but the only problem is in onepage.phtml the shipping html is still rendered there. Also customers still have the option when filling out billing address to choose to use it as their shipping address but I want shipping completely removed and for users to not be able to see it. Thank you for your time in advance and yes I realized you never guaranteed for it to work in my version of Magento.

  • Manish Prakash

    Is your freeshipping method enabled in admin for all order total?

  • test

    I want to remove Review step in Onepage checkout.

  • vinod_disqus

    Thanks a lot man. It works for me..

  • I used the remove shipment method extension, that worked great. Thank you very much.

  • tuanle

    I setup module but alert “Invalid Shipping method”. Can I help you resolve it.

  • karthikphp

    Really Nice code
    I used the extension 1.9.1 version and had an issue:

    After the Billing Information Its skipped the shipping method, but I got the error message as Invalid shipping method may i know how to fix the issue.

  • Anto Nishanth

    How to download the module? I dont find the download link anywhere?

  • Muthu Sicalingam

    i can’t able to download the source file. The download text shows
    [dm]10[/dm]

    • muthulazar

      Reply please as this is urgent need for me