Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active March 13, 2022 19:42
Show Gist options
  • Save cartpauj/45629aa5d6ac83773d9ef2520a8e2aeb to your computer and use it in GitHub Desktop.
Save cartpauj/45629aa5d6ac83773d9ef2520a8e2aeb to your computer and use it in GitHub Desktop.
Remove State Field from MemberPress Signup Forms
<?php
//Remove the State Field completely
function trim_down_address_fields($options) {
foreach($options->address_fields as $i => $o) {
if($o->field_key == 'mepr-address-state') {
unset($options->address_fields[$i]);
}
}
return $options;
}
add_filter('mepr_fetch_options', 'trim_down_address_fields');
//Add a fake state value to each user
function populate_state_field($event) {
$user = $event->get_data();
update_user_meta($user->ID, 'mepr-address-state', 'fake');
}
add_action('mepr-event-login', 'populate_state_field');
//Single page checkout support
function mepr_cust_fake_state($tax_rate, $country, $state, $postcode, $city, $street, $usr = null, $prd_id = null) {
$_POST['mepr_address_state'] = 'fake';
return $tax_rate;
}
add_filter('mepr_find_tax_rate', 'mepr_cust_fake_state', 19, 8);
@nspainting
Copy link

Hi @mbaierl - your code works well for me, thank you so much. How can it be altered to ask for just the country plus zip code?

@mbaierl
Copy link

mbaierl commented Jun 30, 2021

The code does not modify the country or zip code fields; it simply removes the state field.

Hi @mbaierl - your code works well for me, thank you so much. How can it be altered to ask for just the country plus zip code?

@slackday
Copy link

slackday commented Mar 13, 2022

The "fake" value of state will show up in every email template also state cannot seem to be an empty value. Not a great solution but this seem like a MemberPress issue.

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