Support » Fixing WordPress » $_COOKIE variable empty

  • Hi
    I’m a plugin developer and I’m experiencing some issues with cookies.
    I set an action for ‘woocommerce_order_status_changed’ hook and when I try to read cookies in it, I see that there are no cookies.
    This happens to most websites that installed my plugin.
    I released some new versions to figure out the problem and here is what I found:
    This happens on 60 percent of each website’s orders,
    It’s not just about my requested cookies it’s like there are no cookies set at all,
    Current url of the page that calls this action doesn’t matter since it’s sometimes ok and sometimes not on the same url.
    Feel free to ask questions and please help me solve this problem faster.
    Regards

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • On a clean install of WordPress, with Twenty Twenty One theme active and WooCommerce as the only installed plugin, I am seeing the $_COOKIE contents every time I update order status. So I can’t recreate the issue under these conditions. I hope that helps you at least by adding another data point in your investigation.

    add_action('woocommerce_order_status_changed', 'wpsf_woocommerce_order_status_changed', 10, 3);
    function wpsf_woocommerce_order_status_changed($id, $previous_status, $next_status)
    {
      error_log(print_r($id, true));
      error_log(print_r($previous_status, true));
      error_log(print_r($next_status, true));
      error_log(print_r($_COOKIE, true));
    }

    Hi @affiliatenetworks,

    If there’s a cache server or CDN involved, it may be filtering cookies based on a whitelist. This is to improve caching since each request with a unique set of cookies would need to be different from other requests and could not be cached (you may receive a different reply from the server based on your cookies, so the cache server cannot serve you the cached response of a previous client). Since lots of services are setting cookies that may be sent to the server (e.g. analytics packages) but do not influence the contents of the response, heeding all cookies by default would often completely subvert caching.

    Configure the caching server in charge to pay attention to your cookie and to forward it to the origin server. If you have a lot of different cookies, consider giving them a common prefix and whitelist that (e.g. foo-*).

    Hope this helps :)!

    Let me know if my answer can help you resolve your issue!

    Thread Starter affiliatenetworks

    (@affiliatenetworks)

    Hi
    Thank you so much for your helps, it turns out you are write and there is nothing wrong with my plugin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘$_COOKIE variable empty’ is closed to new replies.