4

I need to hand code an affiliate link (we do not want to use an existing plugin). I do not do a lot of coding, so bear with me.

It seems so simple I have a link: http://www.domain.com/?code=8765

Then I want to grab that code number and put it in a cookie. That way if a lead form goes in it can be passed through the API to SalesForce. Can anyone tell me why this isn't working? If the id variable is set to a string it works fine.

Does this even make sense to accomplish this using this method?

add_action( 'init', 'set_agent_cookie' );

function set_agent_cookie() {
    $name = 'agent';
    $id = $_GET['code'];
       setcookie( $name, $id, time() + 3600, "/", COOKIE_DOMAIN );
}
3
  • just tested, your code works perfectly here even with numbers... Commented Oct 18, 2016 at 20:29
  • I may be wrong, but I think this would over write the code if you browse to a page without the variable in the URL. I think you will need to add some logic to only set the cookie if the variable is set. Commented Feb 19, 2017 at 14:21
  • if-then statement to make it a bit better (as solution) can be found here: wordpress.stackexchange.com/questions/257046/… Commented Jun 4, 2019 at 16:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.