Advertisement
Guest User

PMPro Customizations For Specific country on Buddypress pro

a guest
Mar 8th, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: PMPro Customizations
  4. Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
  5. Description: Customizations for PMPro
  6. Version: .1
  7. Author: Stranger Studios
  8. Author URI: http://www.strangerstudios.com
  9. */
  10. //add tax info to cost text. this is enabled if the danish checkbox is checked.
  11. function customtax_pmpro_tax($tax, $values, $order)
  12. {
  13. $tax = round((float)$values[price] * 0.23, 2);
  14. return $tax;
  15. }
  16.  
  17. function customtax_pmpro_level_cost_text($cost, $level)
  18. {
  19. //only applicable for levels > 1
  20. $cost .= "";
  21.  
  22. return $cost;
  23. }
  24. add_filter("pmpro_level_cost_text", "customtax_pmpro_level_cost_text", 10, 2);
  25.  
  26. //add BC checkbox to the checkout page
  27. function customtax_pmpro_checkout_boxes()
  28. {
  29. ?>
  30.  
  31. <?php
  32. $args = array(
  33. 'field' => 'País', // Exact field name or field ID.
  34. 'user_id' => bp_loggedin_user_id() // ID of logged in user
  35. );?>
  36. <?php
  37. $data = bp_get_profile_field_data( $args );
  38. if ( $data == 'Portugal' ) {?>
  39. <div style="display:none" >
  40. <input name="taxregion" type="checkbox" id="taxregion" value="1" checked="checked" <?php if(!empty($_REQUEST['taxregion']) || !empty($_SESSION['taxregion'])) {?>checked="checked"<?php } ?> /></div>
  41. <?php } else {?>
  42. <div style="display:none" >
  43. <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 } ?> />
  44. </div>
  45. <?php }?>
  46.  
  47. <?php
  48. }
  49. add_action("pmpro_checkout_boxes", "customtax_pmpro_checkout_boxes");
  50.  
  51. //update tax calculation if buyer is from portugal
  52. function customtax_region_tax_check()
  53. {
  54. //check request and session
  55. if(isset($_REQUEST['taxregion']))
  56. {
  57. //update the session var
  58. $_SESSION['taxregion'] = $_REQUEST['taxregion'];
  59.  
  60. //not empty? setup the tax function
  61. if(!empty($_REQUEST['taxregion']))
  62. add_filter("pmpro_tax", "customtax_pmpro_tax", 10, 3);
  63. }
  64. elseif(!empty($_SESSION['taxregion']))
  65. {
  66. //add the filter
  67. add_filter("pmpro_tax", "customtax_pmpro_tax", 10, 3);
  68. }
  69. else
  70. {
  71. //check state and country
  72. if(!empty($_REQUEST['bstate']) && !empty($_REQUEST['bcountry']))
  73. {
  74. $bstate = trim(strtolower($_REQUEST['bstate']));
  75. $bcountry = trim(strtolower($_REQUEST['bcountry']));
  76. if(($bstate == "pt" || $bstate == "portugal") && $bcountry = "pt")
  77. {
  78. //billing address is in PT
  79. add_filter("pmpro_tax", "customtax_pmpro_tax", 10, 3);
  80. }
  81. }
  82. }
  83. }
  84. add_action("init", "customtax_region_tax_check");
  85.  
  86. //remove the taxregion session var on checkout
  87. function customtax_pmpro_after_checkout()
  88. {
  89. if(isset($_SESSION['taxregion']))
  90. unset($_SESSION['taxregion']);
  91. }
  92. add_action("pmpro_after_checkout", "customtax_pmpro_after_checkout");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement