Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/326d987a5fa38689c88b3a375cfec14b to your computer and use it in GitHub Desktop.
Save JarrydLong/326d987a5fa38689c88b3a375cfec14b to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will add a percentage based fee to the initial and recurring value when using Stripe
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_increase_level_cost_by_percentage_for_gateway( $level ) {
global $gateway;
// set your percentage here
$percentage = 4; // e.g. 4 = 4% increase
// Bail if percentage is not valid.
if ( ! is_numeric( $percentage ) || $percentage <= 0 ) {
return $level;
}
$percentage = $percentage / 100; // convert to decimal
$increased_initial_payment = $level->initial_payment + ( $level->initial_payment * $percentage ); // calculate the increased initial payment
$increased_recurring_payment = $level->billing_amount + ( $level->billing_amount * $percentage ); // calculate the increased recurring payment
if (
( ! empty( $_REQUEST['gateway'] ) && $_REQUEST['gateway'] == 'stripe' ) ||
( $gateway == 'stripe' )
) {
$level->initial_payment = $increased_initial_payment; //Updates initial payment value
$level->billing_amount = $increased_recurring_payment; //Updates recurring payment value
}
return $level;
}
add_filter( 'pmpro_checkout_level', 'my_pmpro_increase_level_cost_by_percentage_for_gateway' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "3 Methods to Adjust Membership Pricing Based on Payment Gateway" at Paid Memberships Pro here: https://www.paidmembershipspro.com/adjust-membership-pricing-by-payment-gateway/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment