Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JarrydLong/e8db36f5a1c5ac7c6732fe7c60619bb7 to your computer and use it in GitHub Desktop.

Select an option

Save JarrydLong/e8db36f5a1c5ac7c6732fe7c60619bb7 to your computer and use it in GitHub Desktop.
<?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