🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Check if the Product has a Special Price in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 2 min read

One of the most common approaches various businesses try to uplift their sales figure is offering the discount. Magento 2 store owners usually incorporate the discounts on store products by displaying the actual price along with the special price to lure the visitors to shop at discounted rates. After the implementation, the home page or category page displays the actual price as cancelled and the special price as the price to be paid.

When you create a custom page in Magento 2 for the products and assign the fetched price, it assigns the actual price instead of the special prices, which is wrong. So you have to check if the product has a special price in Magento 2 store and assign the same to the products. Here, I have come up with the code to check if the product has a special price in Magento 2.

Methods to check if the product has a special price in Magento 2:

  1. With Object Manager
  2. Block Method

Methods to check if the product has a special price in Magento 2:

1. With Object Manager

<?php
$product_id = 10; //Product ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
 
$orgprice = $_product->getPrice();
$specialprice = $_product->getSpecialPrice();
$specialfromdate = $_product->getSpecialFromDate();
$specialtodate = $_product->getSpecialToDate();
$today = time();
if (!$specialprice)
  $specialprice = $orgprice;
if ($specialprice< $orgprice) {
    if ((is_null($specialfromdate) &&is_null($specialtodate)) || ($today >= strtotime($specialfromdate) &&is_null($specialtodate)) || ($today <= strtotime($specialtodate) &&is_null($specialfromdate)) || ($today >= strtotime($specialfromdate) && $today <= strtotime($specialtodate))) {
        echo 'product has a special price';
    }
}
 
?>

2. Block Method

use Magento\Catalog\Model\ProductFactory;
 
protected $productFactory;
 
public function __construct(ProductFactory $productFactory) {
    $this->productFactory = $productFactory;
}
 
public function getIsSpecialPrice($productId){
 
 
 
    $_product = $this->productFactory->create()->load($productId);
    $orgprice = $_product->getPrice();
    $specialprice = $_product->getSpecialPrice();
    $specialfromdate = $_product->getSpecialFromDate();
    $specialtodate = $_product->getSpecialToDate();
    $today = time();
    if (!$specialprice)
      $specialprice = $orgprice;
    if ($specialprice< $orgprice) {
        if ((is_null($specialfromdate) &&is_null($specialtodate)) || ($today >= strtotime($specialfromdate) &&is_null($specialtodate)) || ($today <= strtotime($specialtodate) &&is_null($specialfromdate)) || ($today >= strtotime($specialfromdate) && $today <= strtotime($specialtodate))) {
            return 1;
        }
    }
    
    return 0;
}

That’s it!

Easy to implement and effective Bring the special prices and show with the products in your custom Magento 2 pages.

Once checked, you can set special prices for products in Magento 2.

Happy Coding!

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.