Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created March 21, 2013 13:35
Show Gist options
  • Select an option

  • Save strangerstudios/5213036 to your computer and use it in GitHub Desktop.

Select an option

Save strangerstudios/5213036 to your computer and use it in GitHub Desktop.
Tax customization code for Paid Memberships Pro to optionally charge Danish tax at checkout.
<?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 Danish sites (originally for PMPro member Tim Clausen)
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 my_pmpro_tax($tax, $values, $order)
{
$tax = round((float)$values[price] * 0.25, 2);
return $tax;
}
function my_pmpro_level_cost_text($cost, $level)
{
//only applicable for levels > 1
$cost .= " Medlemmer i DK vil blive opkraevet 25% moms.";
return $cost;
}
add_filter("pmpro_level_cost_text", "my_pmpro_level_cost_text", 10, 2);
//add Danish checkbox to the checkout page
function my_pmpro_checkout_boxes()
{
?>
<table id="pmpro_pricing_fields" class="pmpro_checkout" width="100%" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>
Danish Residents
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div>
<input id="danish" name="danish" type="checkbox" value="1" <?php if(!empty($_REQUEST['danish']) || !empty($_SESSION['danish'])) {?>checked="checked"<?php } ?> /> Check this box if your billing address is in Denmark.
</div>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action("pmpro_checkout_boxes", "my_pmpro_checkout_boxes");
//update tax calculation if buyer is danish
function my_danish_tax_check()
{
//check request and session
if(isset($_REQUEST['danish']))
{
//update the session var
$_SESSION['danish'] = $_REQUEST['danish'];
//not empty? setup the tax function
if(!empty($_REQUEST['danish']))
add_filter("pmpro_tax", "my_pmpro_tax", 10, 3);
}
elseif(!empty($_SESSION['danish']))
{
//add the filter
add_filter("pmpro_tax", "my_pmpro_tax", 10, 3);
}
}
add_action("init", "my_danish_tax_check");
//remove the danish session var on checkout
function my_pmpro_after_checkout()
{
if(isset($_SESSION['danish']))
unset($_SESSION['danish']);
}
add_action("pmpro_after_checkout", "my_pmpro_after_checkout");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment