Created
September 17, 2025 06:24
-
-
Save JarrydLong/e8db36f5a1c5ac7c6732fe7c60619bb7 to your computer and use it in GitHub Desktop.
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 //do not copy | |
| /** | |
| * This recipe will set the initial amount to the billing amount for a level | |
| * that the current logged in user has held a level of before. | |
| * | |
| * 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_change_initial_amount_existing_members( $level ) { | |
| if( ! is_user_logged_in() ) { | |
| return $level; | |
| } | |
| global $current_user, $wpdb; | |
| $sqlQuery = "SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . esc_sql($current_user->ID) . "' AND membership_id = '".esc_sql( $level->ID )."' AND status NOT IN('refunded', 'review', 'token', 'error') LIMIT 1"; | |
| $old_order_id = $wpdb->get_var($sqlQuery); | |
| if( ! empty( $old_order_id ) && ! empty( (float)$level->billing_amount ) ) { | |
| $level->initial_payment = $level->billing_amount; | |
| } | |
| return $level; | |
| } | |
| add_filter( 'pmpro_checkout_level', 'my_pmpro_change_initial_amount_existing_members', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment