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
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)):
Use getFinalPrice() with product object.
eg.
$_product->getFinalPrice();
This will gives price if special price if it applicable otherwise gives regular price.
-
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))) 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.– DukeCommented Jul 17, 2023 at 9:19