In this tutorial, Today I will explain to how to hide other shipping methods if the free shipping method enables in Magento 2. There are many shipping methods by default provided by Magento 2. It may be possible that in your store there are multiple shipping methods enabled and for some products you want to do like there are only a free shipping methods display when other shipping methods should be hidden. Show At that time, you need to perform the below steps. Let’s see the steps. You may also like this : 1) First of all, Let’s assume that you have created a simple module. Now, create di.xml file for create a plugin to hide shipping methods at app/code/RH/Helloworld/etc/ and paste the below code : <?xml version="1.0"?> <!-- /** * Created By : Rohan Hapani */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Shipping\Model\Shipping"> <plugin name="hide_shipping_methods" type="RH\Helloworld\Plugin\HideShippingPlugin"/> </type> </config>2) Now, Create HideShippingPlugin.php file at app/code/RH/Helloworld/Plugin/ and paste the below code to show only Free Shipping Method : <?php /** * Created By : Rohan Hapani */ namespace RH\Helloworld\Plugin; class HideShippingPlugin { public function aroundCollectCarrierRates( \Magento\Shipping\Model\Shipping $subject, \Closure $proceed, $carrierCode, $request ) { // Hide all shipping methods except free shipping method if ($carrierCode != 'freeshipping') { return false;; } $result = $proceed($carrierCode, $request); return $result; } }Output : That’s it !!! I hope this blog is easy to understand about how to hide other shipping methods if the free shipping method enables in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with a proper solution. Stay Safe and Stay Connected !! In most cases, it happens when you do not want to offer a free shipping method to your customers. But the orders are placed with a free shipping method by default from the admin grid. In that case, as a site owner, you will want to remove or disable a free shipping method from the front end of your Magento 2 store. Well, to resolve this problem, we have come up with the ultimate solution to remove/disable custom free shipping in Magento2 from the front-end. Let’s get started on how to remove/disable the custom free shipping method from the front-end in Magento 2. Steps to remove/disable custom free shipping method from the front-end in Magento 2:
Thus, following the above steps, you can easily Remove/Disable Custom Free Shipping Method from Front-end in Magento 2. If you have any questions or face any kind of problem, please contact us.
Online shoppers look forward to shipping charges and it often becomes the decision point for purchase. Hence, E-commerce store owners need to define the shipping system strategically so that neither the customers are disappointed nor the business has to incur any loss. In the default Magento 2, the admin can enable or disable shipping method from the backend. However, if one wants to enable/disable shipping method programmatically in Magento 2 based on specific conditions, follow the below solution. For instance, you want to enable the free shipping method for a minimum cart total and above. Or, you want to enable a certain shipping service for fixed regions or states only. If the customer’s orders fulfil such condition, then only the shipping method should be enabled or disabled. It can be done with the programmatic solution in this post. Or, you may prefer the Magento 2 Shipping Restrictions extension to restrict shipping methods based on the cart, customer attributes, zip codes, and days of the week! Steps to Enable/Disable Shipping Method Programmatically in Magento 2
Shipping Restrictions Allows restricting shipping methods based on the cart, customer attributes, zip codes, and days of the week for efficient shipping management. |