Skip to content

Instantly share code, notes, and snippets.

@ideadude
Forked from strangerstudios/pmpro-australia-gst.php
Last active January 19, 2023 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ideadude/01c6c1ca08d98470006770bad69bdb2d to your computer and use it in GitHub Desktop.
Save ideadude/01c6c1ca08d98470006770bad69bdb2d to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Australia GST
<?php
/*
Plugin Name: Paid Memberships Pro - Australia GST
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-australia-gst/
Description: Apply Australia GST to Checkouts with PMPro
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
Tax solution for Australia
This solution assume the GST tax rate of 10% from March 15th, 2017. Ask your accountant how much tax you must charge.
More info: https://www.business.gov.au/info/run/tax/register-for-goods-and-services-tax-gst
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 Australia checkbox is checked.
function agst_pmpro_tax($tax, $values, $order)
{
$tax = round((float)$values['price'] * 0.1, 2);
return $tax;
}
function agst_pmpro_level_cost_text($cost, $level)
{
//only applicable for levels > 1
$cost .= __(" Customers in Australia will be charged a 10% GST.", 'pmpro-australia-gst');
return $cost;
}
add_filter("pmpro_level_cost_text", "agst_pmpro_level_cost_text", 10, 2);
//set the default country to Australia
function agst_pmpro_default_country($country) {
return 'AU';
}
add_filter('pmpro_default_country', 'agst_pmpro_default_country');
//add AU checkbox to the checkout page
function agst_pmpro_checkout_boxes()
{
?>
<table id="pmpro_pricing_fields" class="pmpro_checkout" width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>
<?php _e('Australian Residents', 'pmpro-australia-gst');?>
</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_normal pmpro_label-inline pmpro_clickable"><?php _e('Check this box if your billing address is in Australia.', 'pmpro-australia-gst');?></label>
</div>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action("pmpro_checkout_boxes", "agst_pmpro_checkout_boxes");
//update tax calculation if buyer is Australian
function agst_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", "agst_pmpro_tax", 10, 3);
}
elseif(!empty($_SESSION['taxregion']))
{
//add the filter
add_filter("pmpro_tax", "agst_pmpro_tax", 10, 3);
}
else
{
//check state and country
if(!empty($_REQUEST['bcountry']))
{
$bcountry = trim(strtolower($_REQUEST['bcountry']));
if($bcountry == "au")
{
//billing address is in AU
add_filter("pmpro_tax", "agst_pmpro_tax", 10, 3);
}
}
}
}
add_action("init", "agst_region_tax_check");
//remove the taxregion session var on checkout
function agst_pmpro_after_checkout()
{
if(isset($_SESSION['taxregion']))
unset($_SESSION['taxregion']);
}
add_action("pmpro_after_checkout", "agst_pmpro_after_checkout");
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Add the Australian GST Tax Rate to Your Membership Site" at Paid Memberships Pro here: https://www.paidmembershipspro.com/add-the-australian-gst-tax-rate-to-your-membership-site/

@ideadude
Copy link
Author

On December 27, 2022, I updated this to match the fixed/updated fork found here: https://gist.github.com/michaelbeil/9a3a7dd33e273bdeb22fe5827db44b8f

Note the version number for the plugin was not changed. Might be a good idea. We should look into moving this to our "Snippets Library" or making it an official add on.

We are planning general purpose tax handling via a plugin or core PMPro update in the future. So don't want to have too many "official" tax solutions for PMPro out there to maintain and transition.

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