The shipping amount is the value of the total charge taken to deliver your item to your shipping address location in Magento 2.
Magento 2 total shipping amount value for the order is the total charge taken by the shipping service provider and the value of shipping amount will be saved into the sales_order table with shipping_amount and base_shipping_amount field.
You can get the shipping value from the order id using the simple code snippet,
<?php namespace Jesadiya\OrderId\Block; use Exception; use Psr\Log\LoggerInterface; use Magento\Framework\View\Element\Template; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Framework\View\Element\Template\Context; class ShippingAmount extends Template { /** * @var OrderRepositoryInterface */ private $orderRepository; /** * @var LoggerInterface */ private $logger; /** * @var array */ private $data; public function __construct( Context $context, OrderRepositoryInterface $orderRepository, LoggerInterface $logger, array $data = [] ) { $this->orderRepository = $orderRepository; $this->logger = $logger; parent::__construct($context,$data); } /** * @return float|null */ public function getShipingChargeOrder() { $shippingAmount = null; try { $orderId = '1'; $orderData = $this->orderRepository->get($orderId); $shippingAmount = (float)$orderData->getShippingAmount(); } catch (Exception $exception) { $this->logger->error($exception->getMessage()); } return $shippingAmount; } }
Pass your Order id value as dynamic in the getShipingChargeOrder() method in the code. You will get Shipping Value as a response for the specific Order id.
You need to just fetch the Order object by order entity id and get the value of the shipping amount from the fetched order object.
Output:
float 10.99