{"id":1718,"date":"2021-04-18T12:10:13","date_gmt":"2021-04-18T12:10:13","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-selected-shipping-rate-in-magento-2-checkout-page\/"},"modified":"2025-05-22T10:39:14","modified_gmt":"2025-05-22T05:09:14","slug":"get-selected-shipping-rate-in-magento-2-checkout-page","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-selected-shipping-rate-in-magento-2-checkout-page\/","title":{"rendered":"How to Get Selected Shipping Rate in Magento 2 Checkout Page"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Store owners implement various pricing strategies like offering discounts, coupon codes, or even have a system of store credits in order to manage refunds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, sometimes, the customers are eligible for tax exemption such as VAT exemption.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In all these scenarios, the online store owner needs to calculate the exemption on the order total.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Magento 2 store owners, if one wants to implement this exemption on subtotal and shipping rates, one needs to&nbsp;<em><strong>get selected shipping rate in Magento 2 checkout page<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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. Enhance the user experience by providing real-time cost calculation, transparency and essential shipping information by&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/update-checkout-summary-on-selecting-shipping-method-in-magento-2\/\">checkout summary update on selecting shipping method in Magento 2<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Selected Shipping Rate in Magento 2 Checkout Page:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in your block file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Magento\\Block;\n\nuse Magento\\Checkout\\Model\\Session;\n\nclass ShippingRate implements ConfigProviderInterface\n{\n    protected $checkoutSession;\n    protected $quote;\n\n    public function __construct(\n        Session $checkoutSession,\n    )\n    {\n        $this->checkoutSession = $checkoutSession;\n        $this->quote = $checkoutSession->getQuote();\n    }\n\npublic function getShippingRate()\n{\n    $shippingAmount = $this->quote->getShippingAddress()->getShippingAmount();\n}\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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,&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1718","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1718"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1718\/revisions"}],"predecessor-version":[{"id":14374,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1718\/revisions\/14374"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}