-
-
Save cartpauj/45629aa5d6ac83773d9ef2520a8e2aeb to your computer and use it in GitHub Desktop.
<?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); |
Hi Cartpauj,
I was wondering if it is possible to remove any field of your choosing for new sign ups, but have them remain intact for logged in users.
This way people can complete their profile later on.
I have send in a support case with Memberpress regarding this and it may be they respond with a solution as well, but seeing as you seem to be already halfway , I was hoping maybe you could point me in the right direction as well
The reason I would want this, is because I want a higher percentage of people to complete their purchase and according to my CPA/accountant I only need their names , countries and whether they are a business or a consumer... and of course the email for the sign up/purchase.
Now I know there is probably cart software like Woo commerce which can handle this out of the box, but I would rather not add too much junk/plugins for every little function I need ( I may not be much of a programmer but I know that piling up plugins = instability).
Anyway thanks in advance for your time and consideration
Cheers,
Martin
You might be able to get away with it, if you set a fake value on the field when the signup is processed, just like we do above. But if you're doing tax calculations or passing address info to the payment gateways, it might not work super well.
This could cause problems with the Gateway credit card address validations, but here's how you can remove all address fields except for the Country field.
<?php
//Remove all address fields except country
function trim_down_address_fields($options) {
foreach($options->address_fields as $i => $o) {
if($o->field_key != 'mepr-address-country') {
unset($options->address_fields[$i]);
}
}
return $options;
}
add_filter('mepr_fetch_options', 'trim_down_address_fields');
//Add a fake value to the address fields
function populate_state_field($event) {
$user = $event->get_data();
update_user_meta($user->ID, 'mepr-address-one', '123 Street');
update_user_meta($user->ID, 'mepr-address-city', 'Some City');
update_user_meta($user->ID, 'mepr-address-state', 'Some State');
update_user_meta($user->ID, 'mepr-address-zip', '11111');
}
add_action('mepr-event-login', 'populate_state_field');
Cost me a while, but this gist does not work.
The code always returns the VAT of the vendor country.
Working code:
<?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]);
}
$_POST['mepr_address_state'] = 'fake';
}
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');
Hi, Who can help me? I'm selling paid memberships, but I don't need the adress, zip, state or country (all my members are from the same country). I only need the first name, last name and e-mailadress. How do I remove all this adress-items?
@brave-sites are you charging taxes? If not, just disable the MemberPress Address fields in the "Fields" tab of the settings.
@brave-sites are you charging taxes? If not, just disable the MemberPress Address fields in the "Fields" tab of the settings.
Yes, I do charge taxes. 21% is required where I live.. When I disable the taxes, I don´t know if everything ´ll be okay with the tax authorities...
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?
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?
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.
The above code can be installed in a plugin like Code Snippets or My Custom Functions.