function set_new_visitor_cookie() {
      if (is_archive('choose') && is_product_category('choose')) {
        setcookie('choose', 1, time()+3600*24*100, COOKIEPATH, COOKIE_DOMAIN, false);
    }
      if (is_archive('size-12-products-large') && is_product_category('size-12-products-large')) {
        setcookie('size-12-products-large', 1, time()+3600*24*100, COOKIEPATH, COOKIE_DOMAIN, false);
    }
      if (is_archive('size-12-products-regular') && is_product_category('size-12-products-regular')) {
        setcookie('size-12-products-regular', 1, time()+3600*24*100, COOKIEPATH, COOKIE_DOMAIN, false);
    }
      if (is_archive('size-6-products-regular') && is_product_category('size-6-products-regular')) {
        setcookie('size-6-products-regular', 1, time()+3600*24*100, COOKIEPATH, COOKIE_DOMAIN, false);
    }
      if (is_archive('size-6-products-large') && is_product_category('size-6-products-large')) {
        setcookie('size-6-products-large', 1, time()+3600*24*100, COOKIEPATH, COOKIE_DOMAIN, false);
    }
  if ( is_product_category('size-12-products-large') && is_archive('size-12-products-large') && isset($_COOKIE['choose']) ) {
        return $content;
    } else {
        wp_redirect( 'https://example/' );
        exit;

    }
 }
add_action('template_redirect', 'set_new_visitor_cookie');

Unfortunately, this just does a continuous redirect and none of the pages load. I am out of my mind trying to figure this out. The cookies load perfectly when browsing the specific pages.

Read more here: is_archive, is_product_Category and cookies wordpress cause infinite loop


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: