Last active
July 28, 2021 10:11
-
-
Save andrewlimaza/142d959584c3574eda508d1f19a0e73c to your computer and use it in GitHub Desktop.
Apply tax for Canada PMPro example.
This file contains hidden or 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 | |
/** | |
* 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