Home / Archive / MemberPress: Change Country VAT Rate for a Certain Membership
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Change Country VAT Rate for a Certain Membership

The code snippet will modify the VAT rate on registration for a specified membership only if a user purchasing the membership is from a specific country.
The sample code will set the tax rate to “0” (zero) for subscriptions to the membership with the ID of “123”, if the subscriber is from Germany (DE).

Update the code by replacing the dummy ID of “123” with the ID of the actual membership on this line:

if ( $prd_id === 123 && $country === 'DE' ) {

To change the country, the two-letter code (Alpha-2 code) for Germany (DE) should be changed to the two-letter code of the desired country. Also, the country name should be replaced accordingly.. This country code ( DE ) should be replaced on the same line of code mentioned above. The two-letter country ISO codes (Alpha-2 code) are available here.

To modify the tax rate applied in this custom case, replace the "0" value with the needed custom value, on this line:

$tax_rate->tax_rate = 0;

Code Preview
php
<?php
function mepr_cust_tax_rate( $tax_rate, $country, $prd_id ) {
	// If Membership ID 14 and country is Germany 'DE'
	if ( $prd_id === 123 && $country === 'DE' ) {
		$tax_rate->tax_rate = 0; // Set tax rate to 0
	}
	return $tax_rate;
}
add_filter( 'mepr_vat_tax_rate', 'mepr_cust_tax_rate', 10, 3 );

Comments

Add a Comment