Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Created November 19, 2025 12:10
Show Gist options
  • Select an option

  • Save dwanjuki/19f1a06010aaa752ed49c4441cfb00dc to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/19f1a06010aaa752ed49c4441cfb00dc to your computer and use it in GitHub Desktop.
Add 20% tax to all membership checkouts
<?php
/**
* Add 20% VAT tax to all membership checkouts.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/**
* Set tax rate to 20%.
*/
function my_pmpro_tax_rate( $tax, $values, $order ) {
$tax = round( (float) $values['price'] * 0.2, 2 );
return $tax;
}
add_filter( 'pmpro_tax', 'my_pmpro_tax_rate', 10, 3 );
/**
* Edit level cost text for non-free levels to include tax information.
*/
function my_pmpro_tax_level_cost_text( $cost, $level ) {
if ( ! pmpro_isLevelFree( $level ) ) {
$cost .= '20% VAT added at checkout.';
}
return $cost;
}
add_filter( 'pmpro_level_cost_text', 'my_pmpro_tax_level_cost_text', 10, 2 );
/**
* Change the "Tax" line item label on orders to "VAT".
*/
function my_pmpro_get_price_parts_change_labels( $pmpro_price_parts, $pmpro_invoice ) {
if ( ! empty( $pmpro_invoice->tax ) ) {
$pmpro_price_parts['tax']['label'] = 'VAT';
}
return $pmpro_price_parts;
}
add_filter( 'pmpro_get_price_parts', 'my_pmpro_get_price_parts_change_labels', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment