Thank you for waiting, while I performed some tests on my website.
During testing, I noticed that the custom function attached to the hook 'cred_commerce_after_payment_completed' is only executed when a user submits the Toolset post form, which is set to add a product to the cart, and then that product's order is placed, by the same user.
Other than that, if that or some other user directly places the order (i.e. without using the Toolset post form first), through the normal checkout process, the custom function attached to the hook 'cred_commerce_after_payment_completed' is not executed.
Based on these tests, the suppositions that you've made seem incorrect. If you'd like to track the execution of this custom function attached to the hook 'cred_commerce_after_payment_completed', you can include some debugging lines, which can write some entries to the error log, every time this code is executed:
add_action('cred_commerce_after_payment_completed','xxx_advert_update',10,1);
function xxx_advert_update($data)
{
// Debugging output
$t=time();
error_log(date("Y-m-d h:i:sa",$t));
error_log('------------------------------------');
error_log(print_r($data,true));
error_log('==================================================================================================');
// Extract relevant elements from data
$form_id = $data['extra_data'][0]['cred_form_id'];
$post_id = $data['extra_data'][0]['cred_post_id'];
// if form is the Advert Activation Form, set status to 'live' after payment and change end date
if ($form_id==928)
{
$ad_listing_status="Live";
$ad_status_field="wpcf-xxx-ad-status";
update_post_meta($post_id, $ad_status_field, $ad_listing_status);
$xxx_end_date = time() + (365 * 24 * 60 * 60);
$ad_end_field = "wpcf-xxx-ad-end-date";
update_post_meta($post_id, $ad_end_field, $xxx_end_date);
}
}
These extra debugging lines will write the current timestamp and the "$data" array's content, whenever this function will be executed.
Note: Please make sure that error logging is enabled on the website and you can include the following lines in the website's "wp-config.php" file, to enable it:
( ref: hidden link )
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
I hope this helps and please let me know how it goes.