Skip to content

Instantly share code, notes, and snippets.

@geotsiokos
Created August 24, 2022 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geotsiokos/7a54b127c252e4347e30a2fc46cb97f4 to your computer and use it in GitHub Desktop.
Save geotsiokos/7a54b127c252e4347e30a2fc46cb97f4 to your computer and use it in GitHub Desktop.
// Appends Affiliates URL parameter and ID in every URL, when the affiliate cookie exists
add_action( 'template_redirect', 'affiliates_pname_redirect' );
function affiliates_pname_redirect() {
$pname = get_option( 'aff_pname', AFFILIATES_PNAME );
if( isset( $_COOKIE[AFFILIATES_COOKIE_NAME] ) && !$_GET[$pname] ) {
$location = esc_url( add_query_arg( $pname, $_COOKIE[AFFILIATES_COOKIE_NAME] ) );
wp_redirect( $location );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment