Multi-step guest checkout
Multi-step checkout is a common pattern used in e-commerce websites to guide users through the checkout process.
Some of the benefits of using a multi-step checkout process include:
Enhanced user experience: Breaking down the checkout process into multiple steps can make it feel less overwhelming for customers. Each step focuses on a specific task, such as entering shipping information or payment details, which can simplify the process and reduce errors1.
Increased conversion rates: A streamlined, step-by-step process can help reduce cart abandonment rates. Customers are more likely to complete their purchase if the process is clear and straightforward.
Customization and flexibility: Adobe Commerce allows for customization of each step in the checkout process. This means you can tailor the experience to meet the specific needs of your customers, such as offering different payment or shipping options.
The Commerce boilerplate template does not include a multi-step checkout flow by default, but you can easily implement one using Adobe’s drop-in components.
Step-by-step
The following steps describe how to modify the commerce-checkout.js and commerce-checkout.css block files in the boilerplate template to implement a multi-step checkout flow.
This tutorial covers the guest checkout experience. If you want to implement a custom payment method, customer checkout, virtual cart, or any other feature, you’ll need to adapt the code accordingly. The following table shows the features covered in this tutorial:
Feature | Covered |
---|---|
Custom payment method | ❌ |
Customer checkout | ❌ |
Empty cart | ✅ |
Guest checkout | ✅ |
Virtual cart | ❌ |
Order confirmation | ✅ |
Define layout
Define the layout for the checkout using a contextual fragment and reference the DOM elements where the containers need to be rendered. Replace the block content with this fragment.
Render initial containers
Render the initial containers in the corresponding DOM elements that you created in the previous step.
At this point, if you access the page where you are using the block, you should see that all containers are being rendered. The layout still needs some work, so let’s move on to the next step.
Add styles
Add some styles to the layout and containers to make them look good. Open the commerce-checkout.css
file and add the following styles:
Display/remove empty cart
Check if the cart is empty and display a message to the user. To do this, create a new container called EmptyCart
.
Create two utility functions to display or remove the
EmptyCart
container when needed:Add the following declarations at the end of the decorate function to start listening for the
checkout/initialized
andcheckout/updated
events to determine when to display the empty cart.Add the missing handlers for the previous events.
At this point, if you access the checkout page without a cart, you should see the
EmptyCart
container displayed.
Handle shipping method form
You’ve probably noticed that even after initializing the checkout the shipping address form still loads. To resolve this, create a new utility method called
continueToShipping
to remove the skeleton and render the shipping method form when the checkout is initialized.Update the handlers to use the new method.
Enable shipping
In the render initial containers step, we added a call to a non-existing continueToDelivery
method and disabled the CONTINUE TO SHIPPING METHOD button by default. Now we are going to enable the button when the user selects a shipping address and implement the missing method.
Update the
handleCheckoutUpdated
handler to enable the button when the received data contains a selected shipping address.Update the logic inside the
handleCheckoutInitialized
handler to automatically call thecontinueToDelivery
method if the cart already contains the necessary data.Create the
continueToDelivery
function to render all the containers that are relevant to the delivery step.
Enable payment
Similar to the enable shipping step, you now need to add the logic to enable the CONTINUE TO PAYMENT INFORMATION button and implement the missing continueToPayment
method.
Update the logic inside the
handleCheckoutInitialized
handler to automatically call thecontinueToPayment
method if the cart already contains the necessary data.Create the
continueToPayment
function to render all the containers that are relevant to the payment step.
At this point, you should have a fully functional multi-step checkout, but there’s still some work to do. Let’s move on to the last step.
Create order confirmation
The last step to complete the multi-step checkout process is to create an order confirmation page. To make things easy, you can reuse the code from the commerce-checkout.js
block in the boilerplate template.
Copy the
displayOrderConfirmation
function.Copy the
handleCheckoutOrder
handler.Register the
checkout/order
event listener.
Example
See blocks/commerce-checkout-multi-step
in the demos
branch of the boilerplate repository for complete JS and CSS code for the multi-step checkout flow.