Last active
August 15, 2017 15:52
-
-
Save ryanshoover/5ef76d5a9d8396804ff9563892bf5eb1 to your computer and use it in GitHub Desktop.
GeoIP-based pricing pages
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 | |
| // !! Don't paste the <?php line above !! | |
| /** | |
| * Redirect any pricing pages to my country's pricing page | |
| */ | |
| function redirect_pricing_page() { | |
| $path = $_SERVER['REQUEST_URI']; | |
| // If the path doesn't contain /pricing-, abort | |
| if ( ! stristr( '/pricing-', $path ) ) { | |
| return; | |
| } | |
| // If the GeoIp class doesn't exist, abort | |
| if ( ! class_exists( 'WPEngine\GeoIp' ) ) { | |
| return; | |
| } | |
| $geo = WPEngine\GeoIp::instance(); | |
| if ( 'US' === $geo->country() && '/pricing-usa/' !== $path ) { | |
| wp_safe_redirect( site_url( 'pricing-usa' ), 301 ); | |
| exit; | |
| } | |
| if ( 'GB' === $geo->country() && '/pricing-uk/' !== $path ) { | |
| wp_safe_redirect( site_url( 'pricing-uk' ), 301 ); | |
| exit; | |
| } | |
| } | |
| add_action( 'wp', 'redirect_pricing_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment