Below script helpful to get stock data using object manager
$productId = 1;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productStockObj = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface')->getStockItem($productId);
print_r($productStockObj->getData());
OR
Use of this Block Class
namespace Vendor\Module\Block;
use Magento\Framework\View\Element\Template;
use Magento\Backend\Block\Template\Context;
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
class HelloWorld extends Template
{
protected $stockItemRepository;
public function __construct(
Context $context,
StockItemRepository $stockItemRepository
)
{
$this->stockItemRepository = $stockItemRepository;
parent::__construct($context);
}
public function getStockItem($productId)
{
return $this->stockItemRepository->get($productId);
}
}
you can call to this in phtml file :
$id = 1;
$productStock = $block->getStockItem($id);