Forked from JarrydLong/mypmpro-change-price-based-on-gateway.php
Last active
February 5, 2025 14:29
-
-
Save davidmutero/52ec24471d9747db290c5fb12b7c4a68 to your computer and use it in GitHub Desktop.
Add a fee to the initial and recurring value when using Stripe including when a payment plan is selected.
This file contains hidden or 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 | |
/** | |
* This recipe will add a fee to the initial and recurring value when using Stripe | |
* including when a payment plan is selected. | |
* | |
* 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_checkout_level( $level ) { | |
if ( ! empty( $_REQUEST['gateway'] ) && $_REQUEST['gateway'] === 'stripe' ) { | |
$level->initial_payment += 3; // Adds fee to the initial payment | |
$level->billing_amount += 3; // Adds fee to the recurring payment | |
// Check if a payment plan is selected | |
if ( ! empty( $_REQUEST['payment_plan'] ) ) { | |
$payment_plan_id = sanitize_text_field( $_REQUEST['payment_plan'] ); | |
// Adjust payment plan billing amount as well | |
if ( isset( $level->payment_plans ) && is_array( $level->payment_plans ) ) { | |
foreach ( $level->payment_plans as &$plan ) { | |
if ( $plan['id'] == $payment_plan_id ) { | |
$plan['initial_payment'] += 3; // Adds fee to the plan's initial payment | |
$plan['billing_amount'] += 3; // Adds fee to the plan's recurring payment | |
} | |
} | |
} | |
} | |
} | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmpro_checkout_level' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment