add_action('cred_save_data', 'plus_diu_online_kurs',10,2);
function plus_diu_online_kurs ($post_id, $form_data)
{
// Execute for form ID: 123
if ($form_data['id'] == 13882 ) {
// Get currently logged in User ID
// Custom field name
$meta_key = "wpcf-uu";
$dmeta_key = "wpcf-dateuu";
// 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:
Custom field should be updated after payment.
Instead, I got:
Custom field is updated right after moving to checkout page before payment.
Attaching screenshots of the form. Please advise what is wrong?
thank you. I've replaced hook but there are error during payment on the page.
add_action('cred_commerce_after_order_completed', 'plus_diu_online_kurs',10,2);
function plus_diu_online_kurs ($post_id, $form_data)
{
// Execute for form ID: 123
if ($form_data['id'] == 13882 ) {
// Get currently logged in User ID
// Custom field name
$meta_key = "wpcf-uu";
$dmeta_key = "wpcf-dateuu";
// 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);
// Custom field name
$meta_key = "wpcf-uu";
$dmeta_key = "wpcf-dateuu";
// 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);
1. custom fields: uu and dateuu.
2. post form: updateuu linked to payment
3. post form is placed on "Sample page"
4. woocommerce product: updateuu
5. coupon for 100% discount on payment form: 1
EXPECTED RESULTS
Pressing button of the form fields uu and dateuu should be updated.
REQUIRED ACTION
need to place code below into functions.php as I didn't find how to do it via site:
add_action('cred_commerce_after_order_completed', 'plus_diu_online_kurs',10,1);
function plus_diu_online_kurs ($data)
{
// Custom field name
$meta_key = "wpcf-uu";
$dmeta_key = "wpcf-dateuu";
// 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 assume we are talking about post field group "Anton": hidden link
I have done below modifications in above test site:
1) Edit product post, setup the price to 0 hidden link
2) Create a page, and display the post form: hidden link
3) Add one custom code snippet: hidden link
With below codes:
add_action('cred_commerce_after_order_completed', 'plus_diu_online_kurs',10,1);
function plus_diu_online_kurs ($data){
$form_id = $data['extra_data'][0]['cred_form_id'];
$post_id = $data['extra_data'][0]['cred_post_id'];
if($form_id == 29 ) {
// Custom field name
$meta_key = "wpcf-uu";
$dmeta_key = "wpcf-dateuu";
// 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);
}
}
4) Test it in frontend: hidden link
1) submit the form, and complete the payment
2) Dashboard-> Woocommerce-> Orders: hidden link
Find the new order, and change the status to: Completed
3) Check the new post: hidden link
I can see the custom field values are updated correctly.