Add module.xml file in app/code/Magemonkeys/ShippingHide/etc and copy the following code in it:
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magemonkeys_ShippingHide" setup_version="2.0.10"> <sequence> <module name="Magento_Shipping"/> </sequence> </module> </config> |
Add registration.php in app/code/Magemonkeys/ShippingHide and copy the following code in it:
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkeys_ShippingHide', __DIR__ ); |
Add Uninstall.php file in app/code/Magemonkeys/ShippingHide/Setup and copy the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<?php namespace Magemonkeys\ShippingHide\Setup; use Magento\Framework\Setup\UninstallInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory as ConfigCollectionFactory; /** * ShippingHide Uninstall */ class Uninstall implements UninstallInterface { /** * Config Collection Factory * * @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory */ private $_configCollectionFactory; /** * Initialize Setup * * @param ConfigCollectionFactory $configCollectionFactory */ public function __construct( ConfigCollectionFactory $configCollectionFactory ) { $this->_configCollectionFactory = $configCollectionFactory; } /** * Uninstall DB Schema * * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context * @return void */ public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); $this->removeConfig(); $setup->endSetup(); } /** * Remove Config * * @return void */ private function removeConfig() { $path = 'shipping/behavior'; /** @var \Magento\Config\Model\ResourceModel\Config\Data\Collection $collection */ $collection = $this->_configCollectionFactory->create(); $collection->addPathFilter($path); foreach ($collection as $config) { $config->delete(); } } } |
Add config.xml file in app/code/Magemonkeys/ShippingHide/etc and copy the following code in it:
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> <default> <shipping> <behavior> <hide>1</hide> </behavior> </shipping> </default> </config> |
Add di.xml file in app/code/Magemonkeys/ShippingHide/etc and copy the following code in it:
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <!-- plugin --> <type name="\Magento\Shipping\Model\Rate\Result"> <plugin name="Magemonkeys_ShippingHide" type="Magemonkeys\ShippingHide\Plugin\Shipping\Model\Rate\Result" /> </type> </config> |
Add system.xml file in app/code/Magemonkeys/ShippingHide/etc/adminhtml and copy the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <section id="shipping"> <group id="behavior" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="310"> <label>Behavior of Methods</label> <field id="hide" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1"> <label>Hide Mode</label> <comment>Hides any other shipping methods if free shipping is available.</comment> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> </group> </section> </system> </config> |
Add Data.php file in app/code/Magemonkeys/ShippingHide/Helper and copy the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<?php namespace Magemonkeys\ShippingHide\Helper; use Magento\Store\Model\ScopeInterface; use Magento\Framework\App\Helper\AbstractHelper; /** * Shipping Hide Helper */ class Data extends AbstractHelper { /** * Enabled Config Path */ const XML_CONFIG_ENABLED = 'shipping/behavior/hide'; /** * Check Hide mode Functionality Should be Enabled * * @return bool */ public function isEnabled() { return $this->_getConfig(self::XML_CONFIG_ENABLED); } /** * Retrieve Store Configuration Data * * @param string $path * @return string|null */ protected function _getConfig($path) { return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE); } } |
Add Result.php file in app/code/Magemonkeys/ShippingHide/Plugin/Shipping/Model/Rate and copy the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<?php namespace Magemonkeys\ShippingHide\Plugin\Shipping\Model\Rate; use Magemonkeys\ShippingHide\Helper\Data as ShippingHideHelper; /** * Shipping Result Plugin */ class Result { /** * Helper * * @var \Magemonkeys\ShippingHide\Helper\Data */ protected $_helper; /** * Initialize Plugin * * @param ShippingHideHelper $helper */ public function __construct( ShippingHideHelper $helper ) { $this->_helper = $helper; } /** * Return all Rates in the Result * * @param Result $subject * @param Method[] $result * @return Method[] */ public function afterGetAllRates($subject, $result) { if (!$this->_helper->isEnabled()) { return $result; } $rates = $this->getAllFreeRates($result); return (count($rates) > 0) ? $rates : $result; } /** * Return all free Rates in the Result * * @param Method[] $result * @return Method[] */ public function getAllFreeRates($result) { $rates = []; foreach ($result ?: [] as $rate) { if ($rate->getPrice() < 0.0001) { $rates[] = $rate; } } return $rates; } } |
Run CLI Commands
1 2 3 4 5 6 |
rm -rf var/di/* var/generation/* var/cache/* var/log/* var/page_cache/* var/session/* var/view_preprocessed/* pub/static/* php bin/magento setup:upgrade php bin/magento setup:upgrade php bin/magento setup:static-content:deploy -f php bin/magento cache:clean php bin/magento cache:flush |
Result
No method of free shipping
There is a method of free shipping
[crayon-63d3e11af38d7228233953/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.