I have a function to add a dynamic due date to the Countdown Timer widget from Elementor (Pro). With ACF Pro I created a options page with a date and time picker to change the date, but it doesn't work and I cannot see why. I also tried other codes from this page, but they also don't work. I get a timer with 0 days, hours, minutes and seconds or with the date entered via the Elementor edit page.
Here's the code:
add_action( 'elementor/frontend/widget/before_render', function(\Elementor\Element_Base $element){
if ("countdown" != $element->get_name()) return;
$countdown_date = get_post_meta(get_the_id(), "my-date-field",true);
$element->set_settings("due_date",date("Y-m-d H:i",strtotime($countdown_date))) ;
});
Thanks for any help.
Please make sure that you named the Field Name is "my-date-field" and the Field Type is "Date Time Picker"(look at below image for more detail).
If this is not fix your issue then: Do you get any error message on WP Dashboard or Debug console?
Update:
After take a look on your backend and make some debug, i found that you set your custom field is in option page, while this piece of code use to get the value of the custom field base on the post's ID.
To get this value, you will need a different code like this:
add_action( 'elementor/frontend/widget/before_render', function(\Elementor\Element_Base $element){
if ("countdown" != $element->get_name()) return;
$countdown_date = get_field('my-date-field', 'option', false);
$element->set_settings("due_date",date("Y-m-d H:i",strtotime($countdown_date)));
});
Also, please make sure that you set the correct return format to "y-m-d H:i:s" for the code working as below image: