How To Use JavaScript To Pass A Cookie Value To Premium Web Cart?

4 replies
I'll keep this short...

I have an email address stored in a cookie on a Wordpress site.

I would like to pass that cookie value onto Premium Web Cart when the user clicks "add to cart" so they do not have to fill in the email address.

Premium Web Cart allows values to be passed using the URL. They allow the code email=whatever@anything.com to be added at the end of the add to cart url to pass that value to the the shopping cart.

What would the code be that converts the cookie to text, then adds it on to a pre-determined URL, then opens that URL with the email text added?

Any help would be greatly appreciated.
Tthanks
#cart #cookie #javascript #pass #premium #premium web cart #web
  • is Premium Web Cart on the same domain as the wp site which has the cookie?

    I know I could do this for you, Just trying to figure out hte exact situation so I know which way to approach it.
    Signature
    {{ DiscussionBoard.errors[3641439].message }}
  • Profile picture of the author theIMgeek
    To do this purely with javascript you need to put this function into the <HEAD> section of your page code:

    Code:
    <script>
        function getCookie(c_name)
    {
    var i,x,y,ARRcookies=document.cookie.split(';');
    for (i=0;i<ARRcookies.length;i++)
    {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf('='));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf('=')+1);
      x=x.replace(/^s+|s+$/g,'');
      if (x==c_name)
        {
        return unescape(y);
        }
      }
    }
    </script>
    And then the actual link would look like this...

    Code:
    <a href="http://www.shoppingcartpage.com" onclick="this.href=this.href+'?email='+getCookie('email_cookie_name');">Add To Cart</a>
    Hope that helps!

    -Ryan
    Signature
    FREE WSO: Protect and Automatically Deliver Your Digital Products

    Ask the Internet Marketing Geek
    <-- Happy to help with technical challenges
    MiniSiteMaker.org <-- Free software to make your mini-sites fast and easy
    {{ DiscussionBoard.errors[3643355].message }}
    • Profile picture of the author Mirnova
      Originally Posted by theIMgeek View Post

      To do this purely with javascript you need to put this function into the <HEAD> section of your page code:

      Code:
      <script>
          function getCookie(c_name)
      {
      var i,x,y,ARRcookies=document.cookie.split(';');
      for (i=0;i<ARRcookies.length;i++)
      {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf('='));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf('=')+1);
        x=x.replace(/^s+|s+$/g,'');
        if (x==c_name)
          {
          return unescape(y);
          }
        }
      }
      </script>
      And then the actual link would look like this...

      Code:
      <a href="http://www.shoppingcartpage.com" onclick="this.href=this.href+'?email='+getCookie('email_cookie_name');">Add To Cart</a>
      Hope that helps!

      -Ryan
      Thanks Ryan, but I'm getting the email showing up as "undefined".
      I've checked the browser cookies. The email cookie is there.

      I tried the code above changing 'email_cookie_name' to email2 (the cookie name). Also tried it changing c_name in all spots to email2. Also tried it without.

      Am I doing something wrong?
      {{ DiscussionBoard.errors[3659024].message }}
  • Profile picture of the author msaqib301
    If you deletes the cookies it will disappear.
    Signature
    Cheapest Do Follow Blog Commenting Service

    {{ DiscussionBoard.errors[3658468].message }}

Trending Topics