Support

Account

Home Forums General Issues ACF and Contact Form 7 [Updating fields]

Unread

ACF and Contact Form 7 [Updating fields]

  • Hello 🙂

    I have a problem and I need a little help with this. I want to update a field (puntos) that I created for the users.

    The code that I execute is

    `$user_id = get_current_user_id();
    $precio_producto = get_field(‘precio’);
    $puntos_usuario = get_field(‘puntos’, ‘user_’. $user_id);
    $puntos_restantes = $puntos_usuario – $precio_producto;
    $field_key = ‘field_54466d765ea42’;

    update_field($field_key, $puntos_restantes, ‘user_’. $user_id);

    
    Until here, everything works perfectly.
    
    The problem comes when I try to do it  in combination with the plugin "Contact form 7". I want that the field is modified when I send the form. For that I need to use this code in my functions.php:
    
    

    function descuento_puntos() {
    //Web service call goes here
    $user_id = get_current_user_id();
    $precio_producto = get_field(‘precio’);
    $puntos_usuario = get_field(‘puntos’, ‘user_’. $user_id);
    $puntos_restantes = $puntos_usuario – $precio_producto;
    $field_key = ‘field_54466d765ea42’;
    update_field($field_key, $puntos_restantes, ‘user_’. $user_id);
    }
    add_action(‘wpcf7_mail_sent’, ‘descuento_puntos’);`

    And here I don’t get results. The mail is seeded but the update not. Am I doing something wrong?, the update_field() doesn’t function since functions.php?. Sorry, but I’m completely lost. Any help, please?

    Thank you in advance 🙂

Viewing 1 post (of 1 total)

The topic ‘ACF and Contact Form 7 [Updating fields]’ is closed to new replies.