Created
April 2, 2021 17:21
-
-
Save ideadude/4e1a08403ea237ea2b7d67f66457e8d9 to your computer and use it in GitHub Desktop.
Fix the billing amount shown on a user's account with Paid Memberships Pro
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 | |
/** | |
* Change the billing amount and cycle number/period for a user's active membership. | |
* This is useful if the number is out of alignment with the gateway. | |
* Change the variables under "change this stuff" | |
* Then visit /wp-admin/?my_fix_billing_amount=1 as an admin. | |
* Deactivate this snippet after running. | |
*/ | |
function my_fix_billing_amount() { | |
global $wpdb; | |
if ( ! empty( $_REQUEST['my_fix_billing_amount'] ) && current_user_can( 'manage_options' ) ) { | |
// change this stuff | |
$user_id = 31; | |
$billing_amount = '3'; | |
$cycle_number = '1'; | |
$cycle_period = 'month'; | |
// find their memberships users entry | |
$sqlQuery = "SELECT * FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . esc_sql( $user_id ) . "' AND status = 'active' LIMIT 1"; | |
$row = $wpdb->get_row( $sqlQuery ); | |
// Now update it | |
if ( ! empty( $row ) ) { | |
$sqlQuery = "UPDATE $wpdb->pmpro_memberships_users SET billing_amount = '" . esc_sql( $billing_amount ) . "', cycle_number = '" . esc_sql( $cycle_number ) . "', cycle_period = '" . esc_sql( $cycle_period ) . "' WHERE id = " . esc_sql( $row->id ) . " LIMIT 1"; | |
$wpdb->query( $sqlQuery ); | |
echo "Found user with ID #" . $user_id . " and updated their active membership to use the billing values you set."; | |
} else { | |
echo "The user with ID #" . $user_id . " doesn't have an active membership."; | |
} | |
exit; | |
} | |
} | |
add_action( 'init', 'my_fix_billing_amount' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment