Skip Navigation

[Resolved] custom field is updated incorrectly before payment completion

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.

Our next available supporter will start replying to tickets in about 2.42 hours from now. Thank you for your understanding.

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

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2677904

I am trying to:
Paid content should be displayed after payment by user. User presses a button of cred form which direct customer on checkout page. After payment completed custom field value should be updated and paid content should be displayed.

I have code in fucntions.php for this

add_action('cred_commerce_after_order_completed', 'plus_diu_buy_kurs',10,1);
function plus_diu_buy_kurs ($data)
{

$form_id = $data['extra_data'][0]['cred_form_id'];
$post_id = $data['extra_data'][0]['cred_post_id'];

if($form_id == 15934 ) {

// Custom field name
$meta_key = "wpcf-shagchm";
$dmeta_key = "wpcf-dshagchm";

// Fetch the current value of $meta_key for $user_id
$currentValue = get_post_meta($post_id, $meta_key, true);
$dcurrentValue = get_post_meta($post_id, $dmeta_key, true);

// And plus 1 to the $currentValue
$newValue = $currentValue + 1;
$dnewValue = strtotime('Today');
// $dnewValue = date('m.d.y H:i:s');

// Finally, update $meta_key for $user_id with $newValue
update_post_meta( $post_id, $meta_key, $newValue);
update_post_meta( $post_id, $dmeta_key, $dnewValue);

}
}

I expected to see:
User should pay and after this custom field should be updated.
If user go on hidden link page but not pay the field should NOT BE UPDATED.

Instead, I got:
User go on hidden link page and not pay but the field IS UPDATED. And paid content is available for user without completed payment.

Appreciate your help.

Thank you in advance
Anton

#2677965

Hi Anton,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot this, I'll need to see exactly how this Toolset Form and the WooCommerce are set up in the admin area.

Can you please share temporary admin login details, along with the exact steps to test this?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2678423

Thank you for sharing these details, but I keep getting the 'not found' message when trying to access the admin area.

Looks like some hidden admin area access gateway is set. Can you please share the exact steps to use that?

I've set your next reply as private again.

#2678584

Thank you for waiting, while I reviewed your form's setup and performed some testing and research.

Since you'd like the custom field value to update only once the order payment has been completed, it would be more appropriate to use the 'cred_commerce_after_payment_completed' hook instead of 'cred_commerce_after_order_completed':
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_payment_completed

You'll find some useful usage examples and debugging notes, in the following forum replies:

https://toolset.com/forums/topic/cred_commerce_after_payment_completed-data-finds-legacy-data-to-cause-error/#post-2311209

https://toolset.com/forums/topic/reopening-ticket-cred_commerce_after_payment_completed-data/#post-2351695

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.