Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travislima/dc64f95ed27ac50ef594cd1cde9c2906 to your computer and use it in GitHub Desktop.
Save travislima/dc64f95ed27ac50ef594cd1cde9c2906 to your computer and use it in GitHub Desktop.
Only allow shipping to specific Zip Codes for Paid Memberships Pro Shipping.
<?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' );
@laurenhagan0306
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment