Forked from andrewlimaza/my-pmpro-valid-shipping-zip-codes.php
Last active
April 8, 2021 18:25
-
-
Save travislima/dc64f95ed27ac50ef594cd1cde9c2906 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. | |
* You will need to use this code recipe together with the PMPro Shipping Address Add On - https://www.paidmembershipspro.com/add-ons/shipping-address-membership-checkout/ | |
* 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
This recipe is included in the blog post on "Restrict your membership sites shipping locations by specifying valid zip codes." at Paid Memberships Pro here: https://www.paidmembershipspro.com/restrict-your-membership-sites-shipping-locations-by-specifying-valid-zip-codes/