Last active
July 28, 2021 10:29
-
-
Save strangerstudios/6650073 to your computer and use it in GitHub Desktop.
Tax solution for British Columbia, Canada to be used with Paid Memberships Pro
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 | |
/* | |
Plugin Name: PMPro Customizations | |
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/ | |
Description: Customizations for PMPro | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
Tax solution for British Columbia, Canada (originally for PMPro member Daryl Nicholson) | |
This solution assume the PST tax rate of 7% from April 1, 2013. Ask your accountant how much tax you must charge. | |
More info: http://sbinfocanada.about.com/od/pst/a/BC-PST.htm | |
Edit as needed, then save this file in your plugins folder and activate it through the plugins page in the WP dashboard. | |
*/ | |
//add tax info to cost text. this is enabled if the danish checkbox is checked. | |
function customtax_pmpro_tax($tax, $values, $order) | |
{ | |
$tax = round((float)$values[price] * 0.07, 2); | |
return $tax; | |
} | |
function customtax_pmpro_level_cost_text($cost, $level) | |
{ | |
//only applicable for levels > 1 | |
$cost .= " Members in British Columbia will be charged a 7% tax."; | |
return $cost; | |
} | |
add_filter("pmpro_level_cost_text", "customtax_pmpro_level_cost_text", 10, 2); | |
//add BC checkbox to the checkout page | |
function customtax_pmpro_checkout_boxes() | |
{ | |
?> | |
<table id="pmpro_pricing_fields" class="pmpro_checkout" width="100%" cellpadding="0" cellspacing="0" border="0"> | |
<thead> | |
<tr> | |
<th> | |
British Columbia Residents | |
</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td> | |
<div> | |
<input id="taxregion" name="taxregion" type="checkbox" value="1" <?php if(!empty($_REQUEST['taxregion']) || !empty($_SESSION['taxregion'])) {?>checked="checked"<?php } ?> /> Check this box if your billing address is in British Columbia, Canada. | |
</div> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<?php | |
} | |
add_action("pmpro_checkout_boxes", "customtax_pmpro_checkout_boxes"); | |
//update tax calculation if buyer is danish | |
function customtax_region_tax_check() | |
{ | |
//check request and session | |
if(isset($_REQUEST['taxregion'])) | |
{ | |
//update the session var | |
$_SESSION['taxregion'] = $_REQUEST['taxregion']; | |
//not empty? setup the tax function | |
if(!empty($_REQUEST['taxregion'])) | |
add_filter("pmpro_tax", "customtax_pmpro_tax", 10, 3); | |
} | |
elseif(!empty($_SESSION['taxregion'])) | |
{ | |
//add the filter | |
add_filter("pmpro_tax", "customtax_pmpro_tax", 10, 3); | |
} | |
else | |
{ | |
//check state and country | |
if(!empty($_REQUEST['bstate']) && !empty($_REQUEST['bcountry'])) | |
{ | |
$bstate = trim(strtolower($_REQUEST['bstate'])); | |
$bcountry = trim(strtolower($_REQUEST['bcountry'])); | |
if(($bstate == "bc" || $bstate == "british columbia") && $bcountry == "ca") | |
{ | |
//billing address is in BC | |
add_filter("pmpro_tax", "customtax_pmpro_tax", 10, 3); | |
} | |
} | |
} | |
} | |
add_action("init", "customtax_region_tax_check"); | |
//remove the taxregion session var on checkout | |
function customtax_pmpro_after_checkout() | |
{ | |
if(isset($_SESSION['taxregion'])) | |
unset($_SESSION['taxregion']); | |
} | |
add_action("pmpro_after_checkout", "customtax_pmpro_after_checkout"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Non-US Taxes with Paid Memberships Pro" at Paid Memberships Pro here: https://www.paidmembershipspro.com/non-us-taxes-paid-memberships-pro/