A
A
Aricus2019-07-09 17:49:18
HTTP Cookies
Aricus, 2019-07-09 17:49:18

Why are there different cookie sets in wordpress on the page and in ajax?

In wordpress, I wrote cookies in ajax, after which they are correctly displayed in ajax, including after refreshing the page:

add_action('wp_ajax_addtocart', 'addtocart_callback');
add_action('wp_ajax_nopriv_addtocart', 'addtocart_callback');
function addtocart_callback() {

  var_dump($_COOKIE);

  ...
  setcookie('cartQuantity', $cartQuantity, time() + (86400 * 30));
  ...
  wp_die();
}

However, if you just write on the page, for example, in header.php,
var_dump($_COOKIE);
then another cookie set is displayed there, in which there is no cartQuantity.
How to get on page cookies written in ajax?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question