Hello, I’m trying to update a custom user profile field called user_credit using the API payment notification.
All i’m doing is incrementing this field by 1 every time a new payment is made and then save.
When a payment notification comes thru it fires off my php code and changes the field value but does not save it.
I don’t see the User field updated at all on WP User dashboard
When I check The user thru WP Users Dashboard and Click edit user i see the field was Incremented correctly but was not completely saved. If i click on “Update User” button then the changes are saved correctly.
I’m not sure why my code is not saving the changes to that field. Its incrementing the field fine but does not commit the changes and is not saved. Any help would be greatly appreciated.
Thank you…
here is code i’m using in the MU directory for the API notification.
filename is: s2_payment_notification.php
http://example.com/?s2_payment_notification=yes&user_id=%%user_id%%
<?php
add_action('init', 's2_payment_notification');
function s2_payment_notification()
{
if(!empty($_GET['s2_payment_notification']) && $_GET['s2_payment_notification'] === 'yes')
// ↑ In my URL, I have `?s2_payment_notification=yes`, that's what I'm looking for here.
{
if(!empty($_GET['user_id']))
// In my URL, I have `&user_id=%%user_id%%, that's what I'm looking for here.
// http://example.com/?s2_payment_notification=yes&user_id=%%user_id%%
{
// Here I might perform any number of tasks related to this user.
$user_id = (integer)$_GET['user_id'];
// Add user credit when purchase complete from payment gateway
// Assign amount of credit to add to account
$add_credit = 1;
$custom_fields = get_user_option('s2member_custom_fields', $user_id);
// Grab any existing credit from The Unique Custom Field ID configured with s2Member.
$credit_sum = $custom_fields['user_credit'];
$total = $credit_sum + $add_credit;
// Set total credit to field
$custom_fields['user_credit'] = $total;
update_user_option($user_id, 's2member_custom_fields', $custom_fields);
}
exit; // We can exit here. There's no reason to continue loading WordPress in this case.
}
}