Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created January 29, 2018 08:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/33d8a63ab59626553e7de5225ce9feaf to your computer and use it in GitHub Desktop.
Save andrewlimaza/33d8a63ab59626553e7de5225ce9feaf to your computer and use it in GitHub Desktop.
Adding custom tax to Paid Memberships Pro and renaming to admin fees instead.
<?php
/**
* This gist is to add a 20% fee on all orders and rename 'Tax' to 'Admin Fees'.
* Please add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* www.paidmembershipspro.com
*/
/**
* This function will add 20% to all orders using the 'pmpro_tax' filter.
*/
function my_admin_fee( $tax, $values, $order ) {
// Work out 20% tax on current value.
$tax = round( floatval( $values[ 'price' ] ) * 0.2, 2 );
return $tax;
}
add_filter( 'pmpro_tax', 'my_admin_fee', 10, 3 );
/**
* This will rename 'tax' to 'admin fees'
*/
function my_change_tax_to_admin_fees( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Tax' :
$translated_text = __( 'Admin Fees', 'paid-memberships-pro' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_change_tax_to_admin_fees', 20, 3 );
/**
* Adds a notice to checkout so users are aware of being charged the 20% fee.
*/
function my_show_checkout_admin_fee_message() {
echo '<strong><small>Please note that a 20% admin fee charge will be applied.</small></strong>';
}
add_action( 'pmpro_checkout_after_level_cost', 'my_show_checkout_admin_fee_message' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment