Optimizing the One Step Checkout Experience: Removing Shipping Steps Completely
If you’re looking to streamline your e-commerce checkout process by removing shipping steps entirely, you’ve come to the right place. In this blog post, we’ll dive into a practical solution for eliminating those extra steps and improving the overall user experience.
The Current Scenario
As mentioned in the question, you’ve successfully configured one step checkout using a tutorial but are now facing two key challenges:
- Visible Shipping Steps: Even though the shipping steps are being skipped, they remain visible on the page.
- Performance Issues: Jumping to the next step takes longer than expected.
Both of these issues can negatively impact your customers’ experience and potentially lead to cart abandonment. Let’s address them one by one.
Removing Shipping Steps Completely: The Technical Approach
To fully remove the shipping steps from the checkout page, we’ll need to modify some core Magento files and templates. This involves a combination of coding and configuration changes.
Step 1: Overriding the Checkout Template
First, you need to override the checkout_index_index template in your custom theme. Create a new file at:
app/design/frontend/{Your_Theme}/{Package}/Magento_Checkout/templates/index/index.phtml
Replace the contents of this file with the following code:
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<div class="page-wrapper">
<div class="container">
<ol class="checkout-steps">
<?php if ($isCustomerLoggedIn): ?>
<li>
<span class="step-number">1</span>
<span class="step-title"><?= $block->escapeHtml(__('Checkout')) ?></span>
<span class="step-description">
<?= /* @escapeNotVerified */ __("Review your order and shipping information.") ?>
</span>
</li>
<?php else: ?>
<li>
<span class="step-number">1</span>
<span class="step-title"><?= $block->escapeHtml(__('Customer Information')) ?></span>
<span class="step-description">
<?= /* @escapeNotVerified */ __("Enter your contact information.") ?>
</span>
</li>
<?php endif; ?>
<!-- Rest of the steps go here -->
</ol>
<?= $block->getChildHtml('checkoutSteps') ?>
</div>
</div>
Step 2: Removing Shipping Steps in the Controller
Next, we need to update the Magento_Checkout module’s controller. Open:
vendor/magento/module-checkout/Controller/Index/Index.php
Find the following line:
/** @var \Magento\Checkout\Model\Session $checkoutSession */
$checkoutSession = $objectManager->create('Magento\Checkout\Model\Session');
And add this code right after it:
// Remove shipping steps from checkout session
if ($checkoutSession->getQuote()->getIsVirtual()) {
unset($checkoutSession->getQuote()->getShippingAddress());
unset($checkoutSession->getQuote()->getShippingMethod());
}
This modification will ensure that the shipping address and method are removed from the session for virtual products, effectively eliminating the need to display those steps in the one step checkout process.
Optimizing Checkout Performance
To address the performance issue of slow transitions between steps, you can optimize your JavaScript and CSS files. Consider using tools like Gulp or Webpack to minify and compress your assets. Additionally, ensure that your theme is well-optimized and all necessary scripts are loaded asynchronously where possible.
Conclusion
Removing shipping steps from the one step checkout process requires a combination of template overrides and controller modifications. By following the technical approach outlined above, you can create a cleaner, more streamlined user experience for your customers while also improving site performance.
Remember to always backup your files before making changes, especially when dealing with core Magento files. If you’re unsure about any part of the process or want professional assistance, don’t hesitate to contact our team at Laravel Company for expert guidance and support.
Happy coding, and until next time!