1

I Need to set custom shipping rates for table rate shipping method, Through observer in magento2,

By default shipping charges is coming from table rate CSV, I created some condition in observer, Any one have suggestion then please share

Observer code:

$order= $observer->getData('order');
$price = 100;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$quote = $observer->getEvent()->getQuote();  
$quote->getShippingAddress()->setShippingMethod('tablerate_bestway');
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();        
$address = $quote->getShippingAddress();
$address->setShippingAmount($price);
$address->setBaseShippingAmount($price);
$rates = $address->collectShippingRates()->getGroupedAllShippingRates();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.