The shipping method may be flatrate or FedEx or freeshipping, but I want to override this price with $1. How can I do this?
1 Answer
1. Register Plugin
app/code/Acme/StackExchange/etc/di.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Quote\Model\Quote\Address\Rate">
<plugin name="Acme_StackExchange_Plugin_Quote_Model_Quote_Address_RatePlugin"
type="Acme\StackExchange\Plugin\Quote\Model\Quote\Address\RatePlugin" sortOrder="10"/>
</type>
</config>
2. Implement Plugin logic
app/code/Acme/StackExchange/Plugin/Quote/Model/Quote/Address/RatePlugin.php
<?php
declare(strict_types=1);
namespace Acme\StackExchange\Plugin\Quote\Model\Quote\Address;
use Magento\Quote\Model\Quote\Address\Rate;
use Magento\Quote\Model\Quote\Address\RateResult\AbstractResult;
use Magento\Quote\Model\Quote\Address\RateResult\Method;
class RatePlugin
{
public function afterImportShippingRate(
Rate $subject,
Rate $result,
AbstractResult $rate
): Rate {
if ($rate instanceof Method) {
// some logic to checks
// set custom price to method
$result->setPrice(1);
}
return $result;
}
}
-
Hey Vitor, i'm having a issue on cart page too, kind check it when you are free. magento.stackexchange.com/questions/359571/… Commented Sep 5, 2022 at 9:17