Last active
August 3, 2021 06:38
-
-
Save andrewlimaza/65b843e9a907885dec63f4a0017d6005 to your computer and use it in GitHub Desktop.
Custom Tax Structure For Paid Memberships Pro for States/Provinces.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add custom tax to Paid Memberships Pro checkout based on state checkout. | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_custom_tax( $tax, $values, $order ) { | |
// Get state from checkout. | |
$bstate = isset( $_REQUEST['bstate'] ) ? $_REQUEST['bstate'] : ''; | |
if ( empty( $bstate ) ) { | |
return $tax; | |
} | |
$bstate = strtolower( $bstate ); // Make sure bstate field is lowercase. | |
$tax_val = 0.07; // default to 7% tax. | |
if ( $bstate == 'bc' ) { | |
$tax_val = 0.10; // 10% if bstate is BC. | |
} | |
if( $bstate == 'aa' ) { | |
$tax_val = 0.50; // 50% if bstate is AA. | |
} | |
$tax = round((float)$values['price'] * $tax_val, 2); | |
return $tax; | |
} | |
add_filter( 'pmpro_tax', 'my_pmpro_custom_tax', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment