I don’t know if you still need the answer, but here’s working example for you.
Header.php
/*SAVE $_GET['aff'] TO COOKIE*/
if(!isset($_SESSION['aff']) and $_GET['aff']){
$cookie_expire = time()+60*60*24*30;
$_SESSION['aff'] = $_GET['aff'];
setcookie('aff', $_SESSION['aff'], $cookie_expire, "https://wordpress.stackexchange.com/", '.'.$_SERVER['HTTP_HOST']);
}
Functions.php – if you need to pass one parameter
/*APPEND 'aff' PARAMETER IN URL THROUGH WHOLE SITE*/
function wprdcv_param_redirect(){
if(isset($_COOKIE['aff']) and !$_GET['aff']){
$location = esc_url(add_query_arg('aff', $_COOKIE['aff']));
wp_redirect($location);
}
}
add_action('template_redirect', 'wprdcv_param_redirect');
OR: Functions.php – if you need to pass array of parameters
/*APPEND 'aff' PARAMETER IN URL THROUGH WHOLE SITE*/
function wprdcv_param_redirect(){
if(isset($_COOKIE['aff']) and !$_GET['aff']){
$location = esc_url(add_query_arg(array('aff' => $_COOKIE['aff'], 'parameter_key' => 'parameter_value', 'parameter_key_two' => 'parameter_value_two')));
wp_redirect($location);
}
}
add_action('template_redirect', 'wprdcv_param_redirect');