Change to custom shipping address during checkout

Change to custom shipping address during checkout

July 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Change to custom shipping address during checkout

Solving the Shipping Address Change Challenge During Magento Checkout

You’re not alone in facing this persistent issue during the checkout process. Changing the shipping address to a custom one while hiding the “different delivery address” option from customers is indeed tricky. Let’s dive into your problem and explore a step-by-step solution.

Understanding the Current Approach

Your current observer for the checkout_controller_onepage_save_shipping_method event fires correctly, indicating that you’ve configured the XML right. However, the “Please specify a shipping method” exception suggests an underlying issue related to how Magento handles address updates during this particular event.

The key challenge lies in the way Magento expects the shipping method to be set before updating the address. When you hide the delivery address option from customers, Magento doesn’t have the shipping method data it needs to proceed with the address update.

The Solution: Using a Custom Shipping Method

To overcome this hurdle, we’ll create a custom shipping method that allows us to bypass the usual validation process and directly update the shipping address. Here’s how:

  1. Create a New Shipping Model

First, you need to extend the Mage_Shipping_Model_Carrier_Abstract class to build your custom shipping model.

class CustomShipping extends Mage_Shipping_Model_Carrier_Abstract
{
    protected $_code = 'custom';
}
  1. Override the Collect Rates Method

In this method, we’ll directly set the shipping address without going through the usual rate calculation process.

public function collectRates(Mage_Sales_Model_Quote $quote)
{
    // Get the quote object
    $quote = $this->getQuote();

    // Set a dummy rate to satisfy Magento's requirement for a shipping method
    $rate = Mage::getModel('shipping/rate_result_method');
    $rate->setCarrier($this->_code);
    $rate->setCarrierTitle('Custom Shipping');

    // Create the address object and set it as the delivery address
    $address = new Varien_Object();
    $address->exchangeArray([
        'street' => ['123 Main St'],
        'city' => 'New York',
        'region_id' => 0,
        'country_id' => 'US',
        'postcode' => '10001',
        'firstname' => 'John',
        'lastname' => 'Doe',
    ]);

    // Update the quote item with the custom address
    $quote->getBillingAddress()->setStreet($address->street);
    $quote->getShippingAddress()->setStreet($address->street);

    // Add the rate to the result object
    $result = Mage::getModel('shipping/rate_result');
    $result->append($rate);

    return $result;
}
  1. Update the Checkout Observer

In your observer function, you can now set this custom shipping method as the selected method before updating the address.

public function changeShippingAddress(Varien_Event_Observer $observer)
{
    // Get the quote object from the event data
    $quote = $observer->getQuote();

    // Set the custom shipping method as the selected method
    $quote->setData('shipping_method', 'custom:custom');

    // Save the quote to trigger Magento's address update process
    $quote->save();
}

Incorporating LaravelCompany Solutions

For a more comprehensive solution, consider integrating your Magento store with our Laravel Company API. Our API provides advanced features like real-time inventory management and order processing that can be leveraged to optimize this process.

Conclusion

By creating a custom shipping method and setting it as the selected option during checkout, you can successfully override Magento’s default behavior and update the shipping address programmatically. This approach allows you to maintain the billing address entered by the customer while forcibly setting a custom delivery address during the checkout process.

Remember that this solution requires careful testing in your specific environment to ensure compatibility with any existing plugins or customizations. If you encounter further issues, our team at Laravel Company would be happy to assist you with more advanced Magento solutions tailored to your business needs.

Don’t forget to explore our blog for more insights on Magento development and e-commerce best practices. Happy coding!

Checkout Extensions Configuration Customers

Our network