Skip to content

Instantly share code, notes, and snippets.

@alexstandiford
Last active March 6, 2019 20:54
Show Gist options
  • Select an option

  • Save alexstandiford/7ffc7c4d98dcd3a65a2423f2862bf14f to your computer and use it in GitHub Desktop.

Select an option

Save alexstandiford/7ffc7c4d98dcd3a65a2423f2862bf14f to your computer and use it in GitHub Desktop.
Keep Referral Var on Redirect
<?php
/**
* Keeps the referral var when wp_redirect is used.
*/
function affwpsupport_keep_referral_var_on_wp_redirect( $location, $status ) {
if ( function_exists( 'affiliate_wp' ) ) {
// Get the referral variable being used in AffiliateWP.
$referral_var = affiliate_wp()->tracking->get_referral_var();
if ( $_GET[ $referral_var ] ) {
// Append the referral variable and value to the URL after the redirect.
$location = add_query_arg( $referral_var, $_GET[ $referral_var ], $location );
}
}
return $location;
}
add_filter( 'wp_redirect', 'affwpsupport_keep_referral_var_on_wp_redirect', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment