You can get Current Product by creating custom module or by object manager, But I am not refer to use as Object Manager
1. Using Module
Create file app/code/Vendor/Module/Block/Product.php and add following Code.
<?php
namespace Vendor\Module\Block;
class Product extends \Magento\Framework\View\Element\Template
{
protected $_registry;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
)
{
$this->_registry = $registry;
parent::__construct($context, $data);
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getCurrentProduct()
{
return $this->_registry->registry('current_product');
}
}
?>
Now you can get the current product in phtml file.
// print current product data
$currentProduct = $block->getCurrentProduct();
echo $currentProduct->getName()
2. Using Object Manager directly phtml
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$registry = $objectManager->get('\Magento\Framework\Registry');
$currentProduct = $registry->registry('current_product');
echo $currentProduct->getName();
echo $currentProduct->getSku();