14

I'm using CE 1.9.1.0.

I'm trying to remove the Shipping Information and Shipping Method steps from onepage checkout but with no success.

Perhaps someone could help me out or point me in the right direction?

33

Here is what I've done.
I removed the shipping step and used a default shipping method that I know is always going to be available.
Not sure if this is what you need but you can at least use it as a starting point.
Here is my idea.
I created a new module with an enable/disable shipping step config setting, so you can always re-enable the shipping step from the system->configuration section.

So create the module StackExchange_Checkout.
You will need the following files.

app/etc/modules/StackExchange_Checkout.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Checkout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Checkout />
            </depends>
        </StackExchange_Checkout>
    </modules>
</config>

app/code/local/StackExchange/Checkout/etc/config.xml - the configuration file where you define models, blocks and rewrite the onepage checkout block. Also it sets a default shipping method.

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Checkout>
            <version>0.0.1</version>
        </StackExchange_Checkout>
    </modules>
    <global>
        <blocks>
            <checkout>
                <rewrite>
                    <onepage>StackExchange_Checkout_Block_Onepage</onepage><!-- rewrite the onepage chackout block -->
                </rewrite>
            </checkout>
        </blocks>
        <helpers>
            <stackexchange_checkout>
                <class>StackExchange_Checkout_Helper</class>
            </stackexchange_checkout>
        </helpers>
        <models>
            <stackexchange_checkout>
                <class>StackExchange_Checkout_Model</class>
            </stackexchange_checkout>
        </models>
    </global>
    <default>
        <checkout>
            <options>
                <hide_shipping>1</hide_shipping>
                <default_shipping>tablerate_bestway</default_shipping><!-- set the default shipping method code -->
            </options>
        </checkout>
    </default>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <StackExchange_Checkout before="Mage_Checkout">StackExchange_Checkout</StackExchange_Checkout>
                    </modules>
                </args>
            </checkout>
        </routers>
        <translate>
            <modules>
                <StackExchange_Checkout>
                    <files>
                        <default>StackExchange_Checkout.csv</default>
                    </files>
                </StackExchange_Checkout>
            </modules>
        </translate>
    </frontend>
</config>

app/code/local/StackExchange/Checkout/etc/system.xml - the system file that places the enabled/disabled flag for the shipping step

<?xml version="1.0"?>
<config>
    <sections>
        <checkout>
            <groups>
                <options>
                    <fields>
                        <hide_shipping translate="label" module="stackexchange_checkout">
                            <label>Hide shipping method step</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </hide_shipping>
                        <default_shipping translate="label" module="stackexchange_checkout">
                            <label>Default shipping method code</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>110</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </default_shipping>
                    </fields>
                </options>
            </groups>
        </checkout>
    </sections>
</config>

app/code/local/StackExchange/Checkout/Helper/Data.php - the helper that checks if the shipping step should be disabled

<?php
class StackExchange_Checkout_Helper_Data extends Mage_Core_Helper_Abstract 
{
    const XML_HIDE_SHIPPING_PATH = 'checkout/options/hide_shipping';
    const XML_DEFAULT_SHIPPING_PATH = 'checkout/options/default_shipping';
    public function getHideShipping()
    {
        if (!Mage::getStoreConfigFlag(self::XML_HIDE_SHIPPING_PATH)){
            return false;
        }
        if (!$this->getDefaultShippingMethod()){
            return false;
        }
        return true;
    }
    public function getDefaultShippingMethod()
    {
        return Mage::getStoreConfig(self::XML_DEFAULT_SHIPPING_PATH);
    }
}

app/code/local/StackExchange/Checkout/Block/Onepage.php - the overwritten checkout block

<?php
class StackExchange_Checkout_Block_Onepage extends Mage_Checkout_Block_Onepage 
{
    protected function _getStepCodes()
    {
        if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
            return parent::_getStepCodes();
        }
        return array_diff(parent::_getStepCodes(), array('shipping_method'));
    }
}

app/code/local/StackExchange/Checkout/controllers/OnepageController.php - override the onepage controller to set automatically the default shipping method.

<?php
require 'Mage/Checkout/controllers/OnepageController.php';
class StackExchange_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
    public function saveBillingAction()
    {
        if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
            parent::saveBillingAction();
            return;
        }

        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $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'])) {
                /* check quote for virtual */
                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) {
                    //add default shipping method
                    $data = Mage::helper('stackexchange_checkout')->getDefaultShippingMethod();
                    $result = $this->getOnepage()->saveShippingMethod($data);
                    $this->getOnepage()->getQuote()->save();
                    /*
                    $result will have erro data if shipping method is empty
                    */
                    if(!$result) {
                        Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method',
                            array('request'=>$this->getRequest(),
                                'quote'=>$this->getOnepage()->getQuote()));
                        $this->getOnepage()->getQuote()->collectTotals();
                        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

                        $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 (!Mage::helper('stackexchange_checkout')->getHideShipping()){
            parent::saveShippingAction();
            return;
        }
        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);

            $data = Mage::helper('stackexchange_checkout')->getDefaultShippingMethod();
            $result = $this->getOnepage()->saveShippingMethod($data);
            $this->getOnepage()->getQuote()->save();

            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));
        }
    }
}

Clear the cache and you are done.

  • I've just implemented this but get a message telling me that my shipping method is invalid? – Vince Pettit Jul 8 '15 at 11:32
  • @VincePettit. I stated in the answer that I used as default a shipping method that is always available in my case. Maybe the shipping method you use is not always available. – Marius Jul 8 '15 at 20:07
  • How to disable shipping information? – Magento 2 Sep 7 '15 at 13:22
  • @Manojkothari I don't know. – Marius Sep 7 '15 at 13:23
  • @Manojkothari if you add any product as virtual product shipping info and shipment selction will not appear – Butterfly Sep 7 '15 at 14:43
7

Make your product as Virtual Product and it will automatically removed.

  • 1
    Note that in this case you will have to change all products on the site to virtual, which is a crazy amount of work and will work than likely cause issues with other standard Magento processes. – David Manners Jan 26 '15 at 12:53
  • 2
    Ideally it is right thing to do if you don't want to shipping information to be collected because that is what virtual product is for and I dont see it will cause issue with other standar process.. – Siddharth Vaghasia Jan 26 '15 at 12:58
  • This is also true of downloadable products. See here. – quickshiftin Nov 16 '15 at 21:21
7

I have a better solution than the one of @marius which doesn't need any rewrites.

You still need to create an own module, there are tons of tutorials for that so I won't explain it here. You have to create an observer and trigger it via the config.xml. You may have to adapt the template app/design/frontend/base/default/template/checkout/onepage.phtml

In your config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Namepace_Module>
            <version>1.0.0</version>
        </Namepace_Module>
    </modules>

    ....

    <frontend>
        <events>
            <controller_action_postdispatch_checkout_onepage_saveBilling>
                <observers>
                    <namespace_module_skip_shipping_method>
                        <type>singleton</type>
                        <class>namespace_module/observer</class>
                        <method>controllerActionPostdispatchCheckoutOnepageSaveBilling</method>
                    </namespace_module_skip_shipping_method>
                </observers>
            </controller_action_postdispatch_checkout_onepage_saveBilling>

            <controller_action_postdispatch_checkout_onepage_saveShipping>
                <observers>
                    <namespace_module_skip_shipping_method>
                        <type>singleton</type>
                        <class>namespace_module/observer</class>
                        <method>controllerActionPostdispatchCheckoutOnepageSaveBilling</method>
                    </namespace_module_skip_shipping_method>
                </observers>
            </controller_action_postdispatch_checkout_onepage_saveShipping>
        </events>
    </frontend>
</config>

In your Model/Observer.php

class Namepsace_Module_Model_Observer {
/**
     * @param Varien_Event_Observer $observer
     */
    public function controllerActionPostdispatchCheckoutOnepageSaveBilling(Varien_Event_Observer $observer)
    {
        if (!Mage::helper('namespace_module')->skipShippingMethod()) {
            return;
        }

        /* @var $controller Mage_Checkout_OnepageController */
        $controller = $observer->getEvent()->getControllerAction();
        $response = Mage::app()->getFrontController()->getResponse()->getBody(true);

        if (!isset($response['default'])) {
            return;
        }

        $response = Mage::helper('core')->jsonDecode($response['default']);

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

            $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
        }
    }

    /**
     * @return string
     * @throws Mage_Core_Exception
     */
    protected function _getPaymentMethodsHtml()
    {
        $layout = Mage::getModel('core/layout');
        $update = $layout->getUpdate();
        $update->load('checkout_onepage_paymentmethod');
        $layout->generateXml();
        $layout->generateBlocks();

        return $layout->getOutput();
    }
}
  • sounds less complicated. Is there a way to check if there is more than one shipping method and only skip step if it's one? – Bernhard Prange Oct 22 '16 at 14:25
  • Can you give full code with explanation? – Prashant Patil Apr 26 '18 at 6:38
-4

I was looking for a easier solution for past few days cause i don't wanted to mess with mage core files. So, I came up with my own solution.

Inspect the div of shipping method and locate the css file. In my case file was at

"pub/static/frontend/myTheme/themeName/en_US/css/stye-m.css"

after that i overwrite the current css, ofcourse i did a backup of my original file.

css:

.step-title,.totals.shipping.incl{display:none !important;}#checkout-shipping-method-load{display:none !important;}

Also, I would like to know if any files are effect with this method. I haven't faced any issue until now.

  • 1
    This file is automatically generated by Magentos static file deployment. Changes will be lost as soon as the files are generated again. – Fabian Schmengler Nov 9 '16 at 8:18
  • 2
    this is not magento 2 question – Jalpesh Patel Jul 12 '17 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.