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.

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
#2683134

I am trying to:

solution proposed here:
https://toolset.com/forums/topic/custom-field-is-updated-incorrectly-before-payment-completion/?bbp_reply_to=2678584&_wpnonce=e351045480#new-post

I expected to see:

after replacement hook to 'cred_commerce_after_payment_completed'

the field should be updated after payment completed

Instead, I got: it still updated before payment.

#2683335

Hi,

I tried to log in to the website's admin area, but it seems to have some hidden/private link for that.

For deeper troubleshooting, I'll need to know the exact steps that you took for this testing, along with the details of the code changes that were made.
(I'll also need your permission to download the clone/snapshot of the website, in case it needs to be investigated on a different server)

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

regards,
Waqar

#2683469
#2683761

Thank you for sharing these details and I was able to access the admin area.

I'll need to perform some tests on my website with a similar setup and code. Will share the findings, as soon as this testing completes.

Thank you for your patience.

#2684183

Just wanted to let you know that I'm still working on this and will share the findings with you today.

#2685176

Thank you for waiting, as this troubleshooting turned out to be more complicated than initially expected.

I found that the following function existed in the active theme's 'functions.php' file:


add_action('cred_save_data', 'plus_one_shagchm',10,2);
function plus_one_shagchm ($post_id, $form_data)
{
    // Execute for form ID: 123
    if ($form_data['id'] == 15672 or 16322 ) {
      ......  
    }
}

However, how this function checks for the submission of specific forms is incorrect. As a result, it is executed for all the forms, not just those whose IDs are specified, and custom field values are updated in cases where they shouldn't.

The correct approach to checking for multiple specific forms is as follows:


add_action('cred_save_data', 'plus_one_shagchm',10,2);
function plus_one_shagchm ($post_id, $form_data)
{
    // Execute for form IDs specified in the array
    $target_forms =  array( 15672 , 16322 );
    if (in_array($form_data['id'], $target_forms)) {
      ......  
    }
}

I hope this helps and please let me know if you need further assistance.