Store owners implement various pricing strategies like offering discounts, coupon codes, or even have a system of store credits in order to manage refunds.
Also, sometimes, the customers are eligible for tax exemption such as VAT exemption.
In all these scenarios, the online store owner needs to calculate the exemption on the order total.
For Magento 2 store owners, if one wants to implement this exemption on subtotal and shipping rates, one needs to get selected shipping rate in Magento 2 checkout page.
The programmatic method to do is shown below using which you can get the selected shipping rate on the checkout page and use it to calculate the exemption for discounts or store credits on order total..
Method to Get Selected Shipping Rate in Magento 2 Checkout Page:
Use the below code in your block file:
class ShippingRate implements ConfigProviderInterface
public function __construct(
$this->checkoutSession = $checkoutSession;
$this->quote = $checkoutSession->getQuote();
public function getShippingRate()
$shippingAmount = $this->quote->getShippingAddress()->getShippingAmount();
If you have any doubts regarding this post, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento Community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.