Forked from strangerstudios/pmpro-australia-gst.php
Last active
April 24, 2020 15:59
-
-
Save travislima/e8e7435d7f4fdf2ee7086777831a70c2 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - South African VAT Plugin (DEVELOPING)
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: Paid Memberships Pro - South Africa VAT | |
Plugin URI: TBA | |
Description: Apply South Africa VAT to Checkouts with PMPro | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
Tax solution for South Africa to add 14% VAT to PMPro Checkout. This Code is not ready for live production and is still being developed. | |
Edit as needed, then save this file to your PMPro Customizations Add On (https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/) | |
*/ | |
//add tax info to cost text. this is enabled if the danish checkbox is checked. | |
function agst_pmpro_tax($tax, $values, $order) | |
{ | |
$tax = round((float)$values[price] * 0.14, 2); | |
return $tax; | |
} | |
function agst_pmpro_level_cost_text($cost, $level) | |
{ | |
//only applicable for levels > 1 | |
$cost .= __(" Customers in South Africa will be charged a 14% VAT.", 'pmpro-australia-gst'); | |
return $cost; | |
} | |
add_filter("pmpro_level_cost_text", "agst_pmpro_level_cost_text", 10, 2); | |
//set the default country to South Africa | |
function agst_pmpro_default_country($country) { | |
return 'ZA'; | |
} | |
add_filter('pmpro_default_country', 'agst_pmpro_default_country'); | |
//add ZA 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('South African 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_clickable"><?php _e('Check this box if your billing address is in South Africa.', '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 danish | |
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 == "za") | |
{ | |
//billing address is in ZA | |
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment