Skip Navigation

[Resolved] How to use cred_commerce_after_payment_completed to update Usermeta

This support ticket is created 5 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Shane 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1195606

I have a form (id=107) that is linked to a Woocommerce product.

I want to update a custom user field for the post author when the purchase is successful.

How do I use cred_commerce_after_payment_completed to do this? If possible, can you please provide a sample code snippet to help?

Thanks in advance.

#1195612

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Amin,

Thank you for contacting our support forum.

Could you let me know what kind of field this is ? Also is it for the current users ?

Finally I would need to know the slug of the custom field that you would like to update.

Thanks,
Shane

#1195618

Hi Shane,

It's a "Single Line" field. I want to add the text "Paid" in that field once the payment is complete.

This would happen for the currently logged in user.

The slug is "is-current-paid-member"

#1195622

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Amin,

The code that is required to update this is.

add_action( 'cred_commerce_after_payment_completed', 'cust_update_user_field', 10, 1 );
function cust_update_user_field( $data ) {
$userid = get_current_user_id();
update_user_meta( $userid, 'wpcf-is-current-paid-member', 'Paid');
}

Please try adding this and let me know if this helps.
Thanks,
Shane

#1195631

Thanks Shane. I want this to run only for the specific form with ID=107. Can you update the code accordingly, please?

#1195656

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Amin,

You can try doing this.


add_action( 'cred_commerce_after_payment_completed', 'cust_update_user_field', 10, 1 );
function cust_update_user_field( $data ) {
if ($data['extra_data']['cred_form_id'] == 107){
$userid = get_current_user_id();
update_user_meta( $userid, 'wpcf-is-current-paid-member', 'Paid');
}
}

Please let me know if this one helps.

Thanks,
Shane

#1198036

Hi Shane,

This code doesn't work. Can you please check the code to make sure it's correct.

Thanks,
Amin

#1198425

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Amin,

That is strange as the code should work.

Would it be possible to gain access to the site that you are testing this on ?

Also to understand the debugging that is required, does the code work correctly when you submit the form and made your test payment before adding the conditional for a specific form ID ?

Please let me know as soon as possible so we can fix this for you 🙂

Thanks,
Shane