Source: CoPilot
Add the following code to functions.php in a child theme. This adds the field ‘_my_date_ymd‘ to the custom fields drop down in the Divi display conditions.
Change +0 in strtotime(‘+0 day’) as needed
- +0 is today
- -1 is yesterday
- +1 is tomorrow
// START Add Global Dynamic date field to hide Booking widgets with a Divi Display Condition
function add_my_date_field($post_id) {
// Only run on singular pages/posts
if (!is_singular() || is_admin()) return;
// Get the date in Ymd format
$mydate = date('Ymd', strtotime('+0 day'));
// Save as a custom field (temporary, per page load)
update_post_meta($post_id, '_my_date_ymd', $mydate);
}
add_action('wp', function() {
if (is_singular()) {
add_my_date_field(get_the_ID());
}
});
// END Add Global Dynamic date field to hide Booking widgets with a Divi Display ConditionCode language: PHP (php)