How To Auto Select Shipping Method in Magento 2
Do you wish to enable Magento 2 auto select shipping method?π
In Magento 2, it is possible to configure multiple shipping methods. On the checkout page, the customers can select their preferred shipping method and proceed further. In this stage, the customers may re-think about purchasing the product if the selected shipping method is too costly. This may also add friction along the customer’s path to conversion.
Pre-selecting the most-convenient shipping method on the checkout page can make things better. Recently, I came across such a requirement of one of our clients. The client wanted to pre-select a specific payment method in Magento 2 for orders exceeding $100 order total.
In this tutorial, I am going to show you how to auto select shipping method in Magento 2. π¦
Method to Auto Select Shipping Method in Magento 2
In order to auto select shipping method in Magento 2, we will use the selectShippingMethodAction()
function.
You can follow the steps below to auto select shipping methods in Magento 2:
- Step 1:Β Copy the vendor\magento\module-checkout\view\frontend\web\js\model\checkout-data-resolver.jsΒ file and paste it atΒ app\design\frontend\Themes\Yourtheme\Magento_Chekout\web\js\model\checkout-data-resolver.js.
- Step 2:Β Now, open the file and search for the following code:
12345if (ratesData.length === 1) {//set shipping rate if we have only one available shipping rateselectShippingMethodAction(ratesData[0]);return;}
1234if(quote.totals()['grand_total'] > 100){selectShippingMethodAction(ratesData[1]);return;}
You can alter the above code as per your condition and the shipping method.
Ending Words
Customer experience is a crucial aspect of online stores. Enhancing every part of the customer’s journey can help you achieve an optimum conversion rate. The above method enables you to auto select shipping method in Magento 2 and improves the customer experience by pre-selecting the most convenient shipping method.
This way, you can smoothen the customer’s journey and enhance conversion rate. π
If you are still facing any issues or have any queries, feel free to comment. I’d be happy to help you! π
Was this solution helpful? Let us know by rating this post. π
Also, do not forget to share this guide with your friends via social media. π
Increase your business profit by restricting shipping methods based on conditions. Explore our extension now!
Prev
How to Add Terms and Conditions to Shopify
Solved: Undefined Index: DirectiveName in SimpleDirective.php in Magento 2
Next