-
-
Save andrewlimaza/883452f13b96a7427378974a36308053 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Update user meta when a recurring payment occurs and an order is created inside Paid Memberships Pro. | |
* Follow this guide to add code to your WordPress site - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* Hook reference: https://www.paidmembershipspro.com/hook/pmpro_subscription_payment_completed/ | |
*/ | |
function my_change_meta_on_payment_received( $morder ) { | |
update_user_meta( $morder->user_id, 'meta_key', 'my value' ); | |
} | |
add_action( 'pmpro_subscription_payment_completed', 'my_change_meta_on_payment_received', 10, 1 ); |
Hi @kylehi2222,
This looks correct to me. 👍
Hello Andrew, many thanks for your post.
I'm trying to use it but unfortunately I get 2 issues and I hope to fix it...
- It seems not work with recurring payments.
Paypal (by IPN) send: txn_type=recurring_payment_profile_created"
In the file ... wp-content/plugins/paid-memberships-pro/services/ipnhandler.php at LINE 61 it's written:
"PayPal Express
- we will get txn_type express_checkout, or recurring_payment_profile_created, or ..."
I cannot find such rule/action about recurring_payment_profile_created, I think that this is why it doesn't work.
- As the action of this hook is: "Update user meta on subscription payment completed for Paid Memberships Pro." I'm using it to Update user meta.
The only MAIL seeded to user after payment is the INVOICE MAIL, I'm adding info about the User Meta updated by the Hook to inform the user after payment. Unfortunately it does not work fine as it send the data BEFORE the update.
In the LINE 798 of the file: wp-content/plugins/paid-memberships-pro/services/ipnhandler.php there is the code:
` //email the user their invoice
$pmproemail = new PMProEmail();
$pmproemail->sendInvoiceEmail( get_userdata( $last_order->user_id ), $morder );
//hook for successful subscription payments
do_action( "pmpro_subscription_payment_completed", $morder );
Why the HOOK is placed after the INVOICE MAIL?
Could you help me to understand and suggest a way to adjust these 2 questions please?
Many thanks. Best Regards
`
Hi
I am also working on the same concept.
So Every time when recurring payment is made, I want to update the user meta data. I tried your solution . buts its not working for me.
Can you help me to resolve this , here is my code
function my_change_meta_on_payment_received( $morder ) {
$membership_id = $morder->membership_level->id;
$pmpro_membership_post_limit1 = get_pmpro_membership_level_meta(
$membership_id,
"pmpro_membership_post_limit",
true
);
update_user_meta( $morder->user_id, 'product_limit', $pmpro_membership_post_limit1 );
}
add_action( 'pmpro_subscription_payment_completed', 'my_change_meta_on_payment_received', 10, 1 );
Hi there,
Thanks for this Andrew. Do you think you could take a moment to check my code:
`function my_change_meta_on_payment_received( $morder ) {
}
add_action( 'pmpro_subscription_payment_completed', 'my_change_meta_on_payment_received', 10, 1 );
`