• Hi,

    With this hook I can change the value of an advanced custom field. It works.

    The only thing that doesn′t work: It does not prevent the mail from being sent if $new_value is not bigger than 0.

    add_action("wpcf7_before_send_mail", "change_contingent_handler");

    function change_contingent_handler($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
    $form_data = $submission->get_posted_data();

    if ($form_data['kont'] != "" ) {
    $kont = $form_data['kont'];
    $reservierungen = 1;
    $new_value = $kont - $reservierungen;

    if (isset($form_data['postid'])) {
    $post_id = $form_data['postid'];
    }

    if ( $new_value > 0 ) {
    if (function_exists('update_field')) {
    update_field($field_key, $new_value, $post_id);
    } else {
    // Error: ACF not available.
    }

    } else {
    // Clear the email content to prevent sending
    add_filter('wpcf7_skip_mail','__return_true');
    }
    }
    }
    }

    I cannot find the error. The form will be submitted resp. the email will be sent, even if $new_value is 0 for example.

    I already tried $submission->skip_mail = true; as well, didn′t work.

    The form submitting process should be interrupted, if $new_value is not bigger than 0.

    Additionally there should be a message (eg. “pls. change the number of participants to a max. of xxx”).

    And after correcting the value, the user should be able to submit the form once more.

    Best regards and thank you in advance

    Markus

    • This topic was modified 1 month, 2 weeks ago by webmark487.
    • This topic was modified 1 month, 2 weeks ago by webmark487.
    • This topic was modified 1 month, 2 weeks ago by webmark487.
    • This topic was modified 1 month, 2 weeks ago by webmark487.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.