Forked from andrewlimaza/my_admin_fees_example.php
Last active
September 29, 2021 20:09
-
-
Save MaryOJob/99681a3b578d9f4d5a1417d54e36354c to your computer and use it in GitHub Desktop.
Adding custom tax to Paid Memberships Pro and renaming to vat fees instead.
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 // do not copy this line | |
/** | |
* This gist is to add a 20% fee on all orders and rename 'Tax' to 'VAT 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 'VAT Fees' | |
*/ | |
function my_change_tax_to_admin_fees( $translated_text, $text, $domain ) { | |
switch ( $translated_text ) { | |
case 'Tax' : | |
$translated_text = __( 'VAT 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% VAT 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