For anyone else who needs help with a similar problem, here is the fix via One Total Care.
- Create a new shortcode using PHP.
// =============================================================================
// Custom Shortcode to deduct 90 days to the event date
// =============================================================================
function themeco_remaining_days_shortcode($atts) {
// Extract attributes
$atts = shortcode_atts(array(
‘key’ => ‘WooCommerceEventsDate’, // Meta key for the event date
), $atts);
// Get the event date from post meta
$event_date = get_post_meta(get_the_ID(), $atts[‘key’], true);
// Check if the event date is valid
if (empty($event_date)) {
return ‘0’; // Return 0 if no event date is found
}
// Create DateTime objects for the current date and event date
$current_date = new DateTime(); // Current date
$event_date_obj = new DateTime($event_date); // Event date
// Calculate the difference between the two dates
$interval = $current_date->diff($event_date_obj);
// Get the number of days remaining
$days_remaining = $interval->days;
// Check if the event is in the past
if ($current_date > $event_date_obj) {
return ‘0’; // Return 0 if the event has already passed
}
// Return the number of remaining days as an integer
return $days_remaining;
}
add_shortcode(‘remaining_days’, ‘themeco_remaining_days_shortcode’);
// =============================================================================
This allows you to use [remaining_days key=“WooCommerceEventsDate”] in the condition like this:
[remaining_days key=“WooCommerceEventsDate”] > 0 AND
[remaining_days key=“WooCommerceEventsDate”] <= 90
Otherwise, with Twig enabled, you can use this condition:
{{ global.date({“format”:“Y-m-d”}) }} After {{ post.meta({“key”:“WooCommerceEventsDate”})|date_modify("-90 days")|date(“Y-m-d”) }}