---
title: "How to Get Current Product in Magento 2"
url: "https://magecomp.com/blog/get-current-product-magento-2/"
date: "2020-07-09T18:03:33+00:00"
modified: "2025-02-20T07:20:34+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "General"
  - "Magento 2"
word_count: 320
reading_time: "2 min read"
summary: "Hello Magento Folks,"
description: "Get Magento 2 current product information for example product id, product name, and many other information that are displayed on the product page."
keywords: "General, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Change the Order of Shipping Fields on Checkout Page in Magento 2?"
    url: "https://magecomp.com/blog/change-order-of-shipping-fields-on-checkout-page-magento-2/"
  - title: "Magento 2: How to Add a Column to Products in Category Grid"
    url: "https://magecomp.com/blog/magento-2-add-column-to-products-in-category-grid/"
  - title: "A Comprehensive Guide to Alternate Hreflang Tags for Magento 2 Store"
    url: "https://magecomp.com/blog/guide-to-alternate-hreflang-tags-for-magento-2-store/"
---

# How to Get Current Product in Magento 2

_Published: July 9, 2020_  
_Author: Dhiren Vasoya_  

![How to Get Current Product in Magento 2](https://magecomp.com/blog/wp-content/uploads/2020/07/How-to-Get-Current-Product-in-Magento-2-1024x512.webp)

**Hello Magento Folks,**

What are you all up to? Welcome again to the Magento tutorial blog where today’s topic is How to get Current Product in Magento 2.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-1.webp)](https://magecomp.com/services/hire-magento-programmer/)

Many a time you need to get current product details in Magento 2. The current product information like product id, product name, and many other details are displayed on the product page. There are several ways to get current product details. As we know that Magento is built with many features in that case it also provides a feature in which the registry is included for storing data of the current product.
Let’s start with the steps to Get Current Product in Magento 2.
## Steps to Get Current Product in Magento 2:
**Step 1:** Create one block file on our custom extension
add **Blockname.php** in the following path
**app\code\Vendor\Extension\Block\Blockname.php**

Now add the following code
```
<?php
namespace VendorExtensionBlock;

use MagentoFrameworkViewElementTemplate;

class Blockname extends Template
{

    protected $_registry;

    public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkRegistry $registry,
    )
    {
        $this->_registry = $registry;
        parent::__construct($context);
    }

    public function getCurrentProduct()
    {
        return $this->_registry->registry('current_product');
    }

}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 2:** Now, we will get the current product in the **template phtml** file
```
// print current product data
if ($currentProduct = $block->getCurrentProduct()) {
    echo $currentProduct->getName() . '<br />';
    echo $currentProduct->getSku() . '<br />';
    echo $currentProduct->getFinalPrice() . '<br />';
    echo $currentProduct->getProductUrl() . '<br />';
    print_r ($currentProduct->getCategoryIds()) . '<br />';
}
```

That’s It
## Final Words:
The above described is the easiest way to Get Current Product in Magento 2. Also, share the article with your Magento friends and colleagues. If you have any issues related to Magento 2 then write them down in the comment section below I will solve them for you. Stay tuned and Staf safe.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-5.webp)](https://magecomp.com/magento-malware-removal.html)

**Happy Coding**


---

_View the original post at: [https://magecomp.com/blog/get-current-product-magento-2/](https://magecomp.com/blog/get-current-product-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-06 10:27:29 UTC_  
