Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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
- */
- //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.23, 2);
- return $tax;
- }
- function customtax_pmpro_level_cost_text($cost, $level)
- {
- //only applicable for levels > 1
- $cost .= "";
- 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()
- {
- ?>
- <?php
- $args = array(
- 'field' => 'País', // Exact field name or field ID.
- 'user_id' => bp_loggedin_user_id() // ID of logged in user
- );?>
- <?php
- $data = bp_get_profile_field_data( $args );
- if ( $data == 'Portugal' ) {?>
- <div style="display:none" >
- <input name="taxregion" type="checkbox" id="taxregion" value="1" checked="checked" <?php if(!empty($_REQUEST['taxregion']) || !empty($_SESSION['taxregion'])) {?>checked="checked"<?php } ?> /></div>
- <?php } else {?>
- <div style="display:none" >
- <input style="display:none" name="taxregion" type="checkbox" id="taxregion" value="0" checked="CHECKED" <?php if(!empty($_REQUEST['taxregion']) || !empty($_SESSION['taxregion'])) {?>checked="checked"<?php } ?> />
- </div>
- <?php }?>
- <?php
- }
- add_action("pmpro_checkout_boxes", "customtax_pmpro_checkout_boxes");
- //update tax calculation if buyer is from portugal
- 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 == "pt" || $bstate == "portugal") && $bcountry = "pt")
- {
- //billing address is in PT
- 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");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement