Skip to content
Advertisement

PHP calculate past dates from today

I have created a PHP function that calculates how old a WordPress/WooCommerce order is. If the order is older than 90 days it should be canceled. The function used to work perfectly. However, since the new year 2020, it has stopped working. I would assume it’s because the function gets confused about the year since -90 days from today is year 2019. How can I make the calculation work with the past years/2019?

I have tried playing with different date formats from the WordPress codex instead of mdy. However, this doesn’t seem to do any difference.

JavaScript

Advertisement

Answer

You can simplify this a lot by running an UPDATE query with a WHERE clause, to only fetch those orders that are older than 90 days. No need to fetch them all and loop over the results.

You will need to set the post_created to the actual name of your column.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement