When a user buys a license for my product I'm trying to add the number of days remaining (if he has any) to the new 30-day period.
SELECT
SUM(DATEDIFF(access_expires, CURDATE())) + 30 as access_remaining
FROM wp_woocommerce_downloadable_product_permissions
WHERE
user_email = 'user@mail.com' AND
product_id = 8 AND access_expires IS NOT NULL;
UPDATE wp_woocommerce_downloadable_product_permissions
SET
access_expires = DATE_ADD(CURDATE(), access_remaining)
WHERE
user_email = 'user@mail.com' AND
product_id = 8 AND
access_expires IS NULL
It seems like I can't use access_remaining from my previous query in my second query. Please help, if possible without using join. Using mariadb if it means anything.