Question

is there a way to prevent Billing Address modification by all users? After entering billing address in registration i don't want to let users modificate it. Thank you very much.

Was it helpful?

Solution

Notice

What you're asking for becomes tricky when you consider how Magento manages the billing address. Any address can be a billing address. A customer can simply select it from a menu component at various points in the system (ie: checkout, address book screen).

Even if you restrict editing on the "default billing address," this too creates some overhead for you, given that Magento enables you to set any address in your address book as the default billing address. In other words, a customer could edit a "non-billing" address, then set it as the default billing address. It would be cumbersome for you to write code to manage this.

And are you using any third-party extensions which provide address editing on the front-end? There's a lot to think about here.

A Solution

With the disclaimer out of the way, you can simply prevent the ability to edit an address by modifying 2 templates:

# File: app/design/frontend/[package]/[theme]/template/customer/address/book.phtml
...
<h2><?php echo $this->__('Default Addresses') ?></h2>
<ol>
<?php if($_pAddsses = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling()): ?>
    <li class="info-box">
        <div class="title-wrap">
            <h3><?php echo $this->__('Default Billing Address') ?></h3>
            <?php /*<a href="<?php echo $this->getAddressEditUrl(Mage::getSingleton('customer/session')->getCustomer()->getAddressById($_pAddsses)) ?>"><?php echo $this->__('Change Billing Address') ?></a>*/ ?>
        </div>              
        <address class="box-content">
            <?php echo $this->getAddressHtml(Mage::getSingleton('customer/session')->getCustomer()->getAddressById($_pAddsses)) ?>
        </address>
   </li>
<?php else: ?>
    <li class="info-box">
        <h3><?php echo $this->__('Default Billing Address') ?></h3>
        <?php echo $this->__('You have no default billing address in your address book.') ?>
...

See line 9; here we simply comment out the link to edit the address. Not secure, but gives you a place to start.

# File: app/design/frontend/[package]/[theme]/template/customer/address/edit.phtml
...
<?php
/**
 * Edit customer address template
 *
 * @see Mage_Customer_Block_Address_Edit
 */
?>
<?php if($this->getTitle()): ?>
<div class="page-title">
    <h1><?php echo $this->getTitle() ?></h1>
</div>
<?php endif; ?>
<?php if ($address->getId() === Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling()) :?>
<p><?php echo $this->__('Sorry, but you cannot modify this address.'); ?></p>
<?php else : ?>
...
<?php endif; ?>

Below the title, we add some additional logic that checks if the address being edited is the default billing. If so, it will not render the edit form and instead display a generic message.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top