Last active
March 6, 2019 20:54
-
-
Save alexstandiford/7ffc7c4d98dcd3a65a2423f2862bf14f to your computer and use it in GitHub Desktop.
Keep Referral Var on Redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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