-3

I'm creating a WooCommerce plugin,

How to execute javascript code (wait to finish it), get a value from a method and use the variable in php code using Wordpress and WooCommerce?

Everything, after call submit payment button.

Greetings.

1 Answers1

0

Just save it in a cookie:

$(document).ready(function () {
  createCookie("height", $(window).height(), "10");
});

function createCookie(name, value, days) {
  var expires;
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    expires = "; expires=" + date.toGMTString();
  }
  else {
    expires = "";
  }
  document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}

And then read it with PHP:

<?PHP
   $_COOKIE["height"];
?>

You can read more about it here

DreamBold
  • 2,727
  • 1
  • 9
  • 24