Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active May 16, 2023 10:41
Show Gist options
  • Save strangerstudios/4724a8b7a073a1a8d17b96463c45e3d1 to your computer and use it in GitHub Desktop.
Save strangerstudios/4724a8b7a073a1a8d17b96463c45e3d1 to your computer and use it in GitHub Desktop.
Custom tax structure for Paid Memberships Pro where level 1 has no tax and all other levels have 7.25% tax if billing state is CA.
<?php
/*
Custom Tax Example.
- Requires PMPro 1.3.13 or higher.
- Leave the tax fields blank in the payment settings.
- Level 1 has no tax.
- Other levels have 7.25% tax for CA customers only.
- We update the price description to include the tax amount.
*/
function my_pmpro_tax($tax, $values, $order)
{
//only applicable for levels > 1
if($order->membership_id > 1)
{
if(trim(strtoupper($order->billing->state)) == "CA")
{
$tax = round((float)$values[price] * 0.075, 2);
}
}
return $tax;
}
add_filter("pmpro_tax", "my_pmpro_tax", 10, 3);
function my_pmpro_level_cost_text($cost, $level)
{
//only applicable for levels > 1
if($level->id > 1)
{
$cost .= " Customers in CA will be charged 7.25% tax.";
}
return $cost;
}
add_filter("pmpro_level_cost_text", "my_pmpro_level_cost_text", 10, 2);
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Custom Tax Structure Using the pmpro_tax Hook" at Paid Memberships Pro here: https://www.paidmembershipspro.com/custom-tax-structure-using-the-pmpro_tax-hook/

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