Created
January 7, 2019 11:49
-
-
Save andrewlimaza/1764b2e9cafc89470084561edc119239 to your computer and use it in GitHub Desktop.
Only allow shipping to specific Zip Codes for Paid Memberships Pro Shipping.
This file contains 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 | |
/** | |
* This will only allow users to checkout with specific zip codes for the Shipping Add On for Paid Memberships Pro. | |
* Add the code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_valid_zip_codes( $pmpro_continue_registration ) { | |
// Check if things aren't okay, if not, lets not run this code further. | |
if( ! $pmpro_continue_registration ) { | |
return $pmpro_continue_registration; | |
} | |
$valid_zip_codes = array( '1234', '5678', '1448' ); // Create an array of zip codes that are valid. | |
// Check if the shipping zipcode is valid. | |
$shipping_zip_code = $_REQUEST['szipcode']; | |
// If it's not valid, stop registration and show an error. | |
if ( ! in_array( $shipping_zip_code, $valid_zip_codes ) ) { | |
pmpro_setMessage("Sorry, we do not ship to that area. Please choose an alternative address.", "pmpro_error"); | |
$pmpro_continue_registration = false; | |
} else { | |
$pmpro_continue_registration = true; | |
} | |
return $pmpro_continue_registration; | |
} | |
add_filter( 'pmpro_registration_checks', 'my_pmpro_valid_zip_codes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment