Remove billing section

Magento 1: How to remove billing section from checkout page?

I have recently completed a magento project that customer asked to remove billing section from checkout page. Magento checkout process is quite complex so I decide to just hide that one from magento template.

I suppose you are using RWD default theme and it loads this one page checkout javascript:

skin/frontend/rwd/default/js/opcheckout_rwd.js

I appended  these lines to that one:

$j(document).ready(function(){
    console.log(accordion);
    if(accordion.currentSection == 'opc-billing') {
        billing.save();
    }
    $j("#opc-billing").hide();
    $j("#opc-shipping .step-title").css('border-top', 'none');
    $j("span.number").each(function(){
        var n = parseInt($j(this).text());
        $j(this).text(n-1);
    });
});

And the file source code looks like:

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     rwd_default
 * @copyright   Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

Checkout.prototype.gotoSection = function (section, reloadProgressBlock) {
    // Adds class so that the page can be styled to only show the "Checkout Method" step
    if ((this.currentStep == 'login' || this.currentStep == 'billing') && section == 'billing') {
        $j('body').addClass('opc-has-progressed-from-login');
    }

    if (reloadProgressBlock) {
        this.reloadProgressBlock(this.currentStep);
    }
    this.currentStep = section;
    var sectionElement = $('opc-' + section);
    sectionElement.addClassName('allow');
    this.accordion.openSection('opc-' + section);

    // Scroll viewport to top of checkout steps for smaller viewports
    if (Modernizr.mq('(max-width: ' + bp.xsmall + 'px)')) {
        $j('html,body').animate({scrollTop: $j('#checkoutSteps').offset().top}, 800);
    }

    if (!reloadProgressBlock) {
        this.resetPreviousSteps();
    }
}

$j(document).ready(function(){
    console.log(accordion);
    if(accordion.currentSection == 'opc-billing') {
        billing.save();
    }
    $j("#opc-billing").hide();
    $j("#opc-shipping .step-title").css('border-top', 'none');
    $j("span.number").each(function(){
        var n = parseInt($j(this).text());
        $j(this).text(n-1);
    });
});

You should remember to remove checkout progress from the right column to make it consistent by doing these steps:

Copy base app/design/frontend/base/default/template/checkout/onepage/progress/billing.phtml default template to

app/design/frontend/rwd/default/template/checkout/onepage/progress/billing.phtml
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php if ($this->getCheckout()->getStepData('billing', 'complete')): ?>
<dt class="complete">
    <?php echo $this->__('Billing Address') ?><span class="changelink"> <span class="separator">|</span> <a
        href="#billing"
        onclick="checkout.changeSection('opc-billing'); return false;"><?php echo $this->__('Change') ?></a></span>
</dt>
<dd class="complete">
    <address><?php echo $this->getBilling()->format('html') ?></address>
</dd>
<?php else: ?>
<dt>
    <?php echo $this->__('Billing Address') ?>
</dt>
<?php endif; ?>

after that removing all source code from this file

<?php
//nothing to show

I had to write a simple magento extension to update billing address for all registered customers.

app/code/local/Beehexa/Customerbilling/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Beehexa_Customerbilling>
            <version>0.1.0</version>
        </Beehexa_Customerbilling>
    </modules>	
    <global>	
        <customerbilling>
                <class>Beehexa_Customerbilling_Model</class>
        </customerbilling>	
        <events>
            <customer_save_before>
                <observers>
                    <Beehexa_Customerbilling>
                        <type>singleton</type>
                        <class>Beehexa_Customerbilling_Model_Observer</class>
                        <method>updateCustomerBilling</method>
                    </Beehexa_Customerbilling>
                </observers>
            </customer_save_before>
            
            <customer_register_success>
                <observers>
                    <Beehexa_Customerbilling>
                        <type>singleton</type>
                        <class>Beehexa_Customerbilling_Model_Observer</class>
                        <method>updateCustomerBilling</method>
                    </Beehexa_Customerbilling>
                </observers>
            </customer_register_success>            
            
        </events>	
    </global>	
</config>
app/code/local/Beehexa/Customerbilling/Model/Observer.php
<?php

class Beehexa_Customerbilling_Model_Observer {

    public function updateCustomerBilling($event) {
        $customer = $event->getCustomer();
        if($customer->getId())
        {
            $address = $customer->getPrimaryBillingAddress();
        } else {
            return;
        }
        
        if ($address)
            return;
        
        $data = [
            'street' => 'default street',
            'company' => 'company',
            'postcode' => '55555',
            'region' => 'Georgia',
            'region_id' => '19',
            'city' => 'Atlanta',
            'firstname' => $customer->getFirstname(),
            'lastname' => $customer->getLastname(),
            'telephone' => '000000000',
            'country_id' => 'US'
        ];
        try {
            $address = Mage::getModel('customer/address');
            $address->setCustomer($customer);
            $address->addData($data);
            $address->save();
            $customer->addAddress($address)
                    ->setDefaultBilling($address->getId())
                    ->save();
        } catch (Exception $ex) {
            Mage::logException($ex);
        }
    }

}

I hope this post can save you time for hiding billing section from magento checkout page.

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email