Pass javascript result to shortcode executer function

I’m really newbie in WordPress development (around 24 hours ago). I’m making a shortcode that executes a short Javascript code, the result of this script I need to get it in the function that executes the shortcode. I have this:

PHP

function range_hour($atts, $content = null){

wp_register_script( ‘custom-script’, plugins_url( ‘assets/js/timezone.js’, __FILE__ ), array( ‘jquery’ ) );
wp_enqueue_script( ‘custom-script’ );
$tz = ‘America/Bogota’;
$timestamp = time();
$dt = new DateTime(“now”, new DateTimeZone($tz));
$dt->setTimestamp($timestamp);
$hour = $dt->format(‘G’);
}

Javascript

Intl.DateTimeFormat().resolvedOptions().timeZone

As you can see in the JS code I’m getting the timezone of the client, until here all fine, but in the PHP code I need to get this result, to replace “America/Bogota” for the JS result. Any ideas how can I achieve this? I’m thinking to make an endpoint, pass the data from JS to that endpoint, but again… How can I get this result in the shortcode function?

Thanks in advanced.

Read more here:: Pass javascript result to shortcode executer function

Leave a Reply

Your email address will not be published. Required fields are marked *