1

I'm using magento 1.9.2.4 and need to remove billing step from onepage checkout and also billing information on the sidebar.

Checkout

I tried with this way but when customer not logged in, customer cannot access the checkout page, it always redirected to homepage or product page.

Any idea? Thanks!

2

Okay, you can do that. The first thing is to enable guest checkout in magento settings, since you want to allow not logged in customers proceed to checkout.

System > Configuration > Checkout > Allow Guest Checkout > Yes

Next step is actually hide Shipping information and use Billing information for both but we will rename it to Delivery Information (you can use Shipping information if you like) and keep checkbox ship to this address always on but not visible to the user.

You need to override Checkout Block Onepage.php with different code to remove shipping information from there

1) You need to add new module into the system (place new module file into the /app/etc/modules/ElectroidLab_StackoverflowCheckout.xml), when add config.xml in your module (local/ElectroidLab/StackoverflowCheckout/etc/config.xml) with the following content:

<?xml version="1.0"?>
<config>
    <modules>
        <ElectroidLab_StackoverflowCheckout>
            <version>0.2.0</version>
        </ElectroidLab_StackoverflowCheckout>
    </modules>
    <global>
        <blocks>
            <checkout>
               <rewrite>
                   <onepage>ElectroidLab_StackoverflowCheckout_Block_Onepage</onepage>
               </rewrite>
           </checkout>
        </blocks>
    </global>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <ElectroidLab_StackoverflowCheckout before="Mage_Checkout">ElectroidLab_StackoverflowCheckout</ElectroidLab_StackoverflowCheckout>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

2) when you need to add file Onepage.php into you module Block folder (local/ElectroidLab/StackoverflowCheckout/Block/Onepage.php)

<?php
class ElectroidLab_StackoverflowCheckout_Block_Onepage extends Mage_Checkout_Block_Onepage {

    /**
     * Get 'one step checkout' step data
     *
     * @return array
     */
    public function getSteps()
    {
        $steps = array();
        $stepCodes = $this->_getStepCodes();

        if ($this->isCustomerLoggedIn()) {
            $stepCodes = array_diff($stepCodes, array('login'));
        }

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

        return $steps;
    }

    /**
     * Get active step
     *
     * @return string
     */
    public function getActiveStep()
    {
        return $this->isCustomerLoggedIn() ? 'billing' : 'login';
    }

    protected function _getStepCodes()
    {
        // Remove shipping from array
        return array('login', 'billing', 'shipping_method', 'payment', 'review');
    }

}

3) Next you need to add file OnepageController.php into you module Block folder (local/ElectroidLab/StackoverflowCheckout/controllers/OnepageController.php)

<?php
/**
 * Onepage controller for checkout
 *
 * @category    Mage
 * @package     Mage_Checkout
 * @author      Magento Core Team <core@magentocommerce.com>
 */

require_once Mage::getModuleDir('controllers', "Mage_Checkout").DS."OnepageController.php";

class ElectroidLab_StackoverflowCheckout_OnepageController extends Mage_Checkout_OnepageController
{


    /**
     * Save checkout billing address
     */
    public function saveBillingAction()
    {
        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'])) {
                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'] = 'shipping_method';
                    $result['update_section'] = array(
                        'name' => 'shipping-method',
                        'html' => $this->_getShippingMethodsHtml()
                    );

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

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


}

4) Next step is to remove ship to this address, ship to different address div, to do that you need to copy billing.phtml from current design theme to your default theme. If you are using rwd package when you need to copy /app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml to your default theme in my case
/app/design/frontend/rwd/stackoverflow/template/persistent/checkout/onepage/billing.phtml (I set stackoverflow as my default theme into the System > Configuration > Design > Themes > Default).

Now you can hide the following div inside billing.phtml :

<?php if ($this->canShip()): ?>
    <input type="hidden" name="billing[use_for_shipping]" value="1" />
<?php endif; ?>

now you won't see ship to this address, ship to different address.

If everything is fine and your module executed within the system you won't see the shipping information step.

5) Now you want to rename Billing Information to Delivery information (as Example, you can use Shipping information if you want), to that you need to create translate.csv within your default theme locale folder, /app/design/frontend/rwd/stackoverflow/locale/en_US/translate.csv and put that code here

"Mage_Checkout::Billing Address","Delivery Address"
"Mage_Checkout::Billing Information","Delivery Information"
"Mage_Checkout::Billing Information - %s","Delivery Information - %s"

you can check other possible fields to translate or rename within /app/locale/en_US/Mage_Checkout.csv

6) You almost done, now only want to remove Shipping from the sidebar of your checkout progress

You need to copy /app/design/frontend/base/default/template/checkout/onepage/progress/shipping.phtml to your design theme /app/design/frontend/rwd/stackoverflow/template/checkout/onepage/progress/shipping.phtml , when just remove everything from that file and you done!

|improve this answer|||||

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