Hi,
Thank you for contacting us and I'd be happy to assist.
Your observation is correct and by the time the 'cred_save_data' hook executes, the custom field values have been updated, based on the form fields.
To overcome this, you can use the 'cred_before_save_data' hook instead:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
Example:
add_action('cred_before_save_data', 'idy_while_saving_the_form',10,1); // While saving data
function idy_while_saving_the_form($form_data) {
$forms = array( 8604, 8598, 8599, 8603, 8613, 8614, 8605, 8612, 8615, 8611, 8616, 35227, 35231 );
if ( in_array( $form_data['id'], $forms ) ) {
$post_id = $_POST['_cred_cred_prefix_post_id'];
$product = wc_get_product( $post_id );
$current_status = get_post_meta( $post_id, 'wpcf-car-status', true);
$new_status = (isset($_POST['wpcf-car-status']) ? $_POST['wpcf-car-status'] : false );
.....
}
}
If you'd like to continue using the 'cred_save_data' hook, you can include a hidden generic field with the slug 'existing-status-value' in the form.
Next, using some custom code, you can copy the value from the 'car-status' field into this hidden generic field:
jQuery(document).ready(function( $ ) {
var existingStatus = $('input[name=wpcf-car-status]').val();
$('input[name=existing-status-value]').val(existingStatus);
});
As a result, when the form will be submitted, you'll be able to obtain the existing field value, using this generic field:
$current_status = $_POST['existing-status-value'];
I hope this helps and please let me know if you need further assistance.
regards,
Waqar