Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active July 28, 2021 10:11
Show Gist options
  • Save andrewlimaza/142d959584c3574eda508d1f19a0e73c to your computer and use it in GitHub Desktop.
Save andrewlimaza/142d959584c3574eda508d1f19a0e73c to your computer and use it in GitHub Desktop.
Apply tax for Canada PMPro example.
<?php
/**
* Apply 13% if a user selects 'Canada'.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Set 13% tax value.
function customtax_pmpro_tax($tax, $values, $order) {
$tax = round( (float)$values[price] * 0.13, 2 );
return $tax;
}
// Apply the tax on load and when returning from PayPal and loading
function customtax_region_tax_check() {
if ( ! function_exists( 'pmpro_start_session' ) ) {
return;
}
// Start the session
pmpro_start_session();
// If bcountry is found in session and value is CANADA apply tax.
if ( isset( $_SESSION['bcountry'] ) && $_SESSION['bcountry'] == 'CA' ) {
add_filter( 'pmpro_tax', 'customtax_pmpro_tax', 10, 3 );
return;
}
// If bcountry is found in session and value is CANADA apply tax.
if ( isset( $_REQUEST['bcountry'] ) && $_REQUEST['bcountry'] == 'CA' ) {
add_filter( 'pmpro_tax', 'customtax_pmpro_tax', 10, 3 );
return;
}
}
add_action( 'init', 'customtax_region_tax_check' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment