I am looking for a way to hook into one of the Magento events that define Order creation Date. I would like to add a counter next to it that shows how many days/weeks/months ago the order was placed.

The reason is some items have extended warranties while others do not so if I could simply calculate the date then customer service could quickly establish whether the item is still covered by the warranty.

I am not sure how I should go about doing this. If anyone would like to lend a hand I would be very grateful for the help...

Thanks in advance!


You can do this via PHP Datetime addition (based on the date of purchase) and set the information on the order at the time of purchase (calculate the date the warranty expires, and store to the order).

Datetime addition, store to quote:

$date = new DateTime($order->getCreatedAt());
$date->add(new DateInterval('P90D'));

If you'd rather calculate it on the fly - it's a very simple change:

$date = new DateTime($order->getCreatedAt());
$date->add(new DateInterval('P90D'));
echo $date->format('Y-m-d');

Further reading:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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