Skip to content

Instantly share code, notes, and snippets.

@ideadude
Forked from strangerstudios/pmpro-customizations.php
Last active March 11, 2020 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/0b7ab2fad5a04d7cea7b8513b527780a to your computer and use it in GitHub Desktop.
Save ideadude/0b7ab2fad5a04d7cea7b8513b527780a to your computer and use it in GitHub Desktop.
Tax solution for British Columbia, Canada to be used with Paid Memberships Pro
<?php
/*
Plugin Name: PMPro Customizations
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Customizations for PMPro
Version: .2
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 } ?> />
<label for="taxregion" class="pmpro_label-inline">Check this box if your billing address is in British Columbia, Canada.</label>
</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");
@ideadude
Copy link
Author

Updated to use a label on the checkbox.

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