Magento 2 checks if the product has a special price

For checking the special price, please follow the below steps:Magento 2 checks if the product has a special price


<?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';
    }
}

How to create a contact us page in Shopify?expoundsofttechsolution

Magento 2 checks if the product has a special price