2

I am trying to add a condition for checked the special price is valid or not for list page but did not able to find.

2 Answers 2

0

After Few Time I found at last:

$specialPriceFromDate = $_product->getData('special_from_date');
$specialPriceToDate = $_product->getData('special_to_date');
$today =  time();

if ($specialprice && ($_product->getData('price') > $_product->getData('final_price'))):
if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || 
    $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)):
-1

Use getFinalPrice() with product object. eg. $_product->getFinalPrice(); This will gives price if special price if it applicable otherwise gives regular price.

3
  • it give but after special price expire also applicable, I want not selected if sepcial price gonna be expired Commented Sep 25, 2018 at 12:06
  • you can find start date and end date in print_r($_product); then compare date as if(strtotime($date1))<strtotime($date2)))
    – user55548
    Commented Sep 25, 2018 at 13:04
  • This is not true, it will return whatever the final price is there. If no special price, it will return the original price as final price.
    – Duke
    Commented Jul 17, 2023 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.