Search code examples
wordpresswhatsappcontact-form-7

How to get select data into Whatsapp button?


This is a simple form (contact form 7) is it possible to get select value in whatsapp button ?

for example please check image

Currently using this button

whatsapp://send?text=Hello! I Need pickup and drop for date &phone=+910000000000

Solution

  • sure, if you are using AJAX to submit your form, you need to hook the cf7 plugin filter, 'wpcf7_mail_sent' which is fired once your form is validated and the notification mail is sent.

    add_filter('wpcf7_mail_sent','get_form_data');
    function get_form_data($form){
      //the submitted data is available in the $_POST session variable.
      $phone_number = $_POST['phone-number']; //where 'phone-number' is your field name.
    }
    

    you can then store these values into a transient to retrieve for building your whatsapp button.

    alternatively, if you are submitting your form using a 'POST' request, then you can simply add this code to your action page,

    if(isset($_POST['phone-number'])){
      $phone_number= $_POST[phone-number];
      // and then continnue to build your whatsapp button.
    }