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