Description
Use to display the custom mail tags to the Google Sheet Pro tab of Contact Form 7 settings and fetch the values using CF7 hook “wpcf7_special_mail_tags” to the google sheet.
Usage
add_filter( “gscf7_special_mail_tags”, “add_custom_mail_tag”, 10, 2 );
Parameters
- $custom_mail_tags : An array to pass the custom mail tag name example “_current_url”.
- $form_id : Contact Form 7 form id.
Example
add_filter( "gscf7_special_mail_tags", "add_custom_mail_tag", 10, 2 ); function add_custom_mail_tag( $custom_mail_tags, $form_id ) { $custom_mail_tags[] = "_current_url"; return $custom_mail_tags; }
To pass values to the Google Sheet, use CF7 hook as following :
add_filter("wpcf7_special_mail_tags", function( $output, $name, $html ) { if ( $name === "_current_url" ) { return "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; } return $output; }, 10, 3 );
Output for above example :
http://demo.gsheetconnector.com/wp-json/contact-form-7/v1/contact-forms/137/feedback
gscf7_special_mail_tags is cf7 gsheetconnector pro hook
add_filter( "gscf7_special_mail_tags", "add_custom_mail_tag", 10, 2 ); function add_custom_mail_tag( $custom_mail_tags, $form_id ) { $custom_mail_tags[] = "_datetime"; return $custom_mail_tags; }add_filter( "wpcf7_special_mail_tags", function( $output, $name, $html ) { if ( $name === "_datetime" ) { $submission = WPCF7_Submission::get_instance(); if ( $timestamp = $submission->get_meta( 'timestamp' ) ) { $date = date_i18n( get_option( 'date_format' ), $timestamp ); $time = date_i18n( get_option( 'time_format' ), $timestamp ); $date_time = $date . " " . $time; return $date_time; } } return $output; }, 10, 3 );// Working with UTM parameters for free version
add_filter( "wpcf7_special_mail_tags", function( $output, $name, $html ) { $submission = WPCF7_Submission::get_instance(); $posted_data = $submission->get_posted_data(); if ( $name === "_utm_source" ) { // Get all posted data here. $output = $posted_data['utm_source']; return $output; } return $output; }, 10, 3 );
add_filter( 'wpcf7_posted_data', 'unset_serial_number_to_posted_data', 10, 1 ); function unset_serial_number_to_posted_data( $posted_data ) { $serial_number = $posted_data['Serial Number']; unset( $posted_data['Serial Number'] ); $posted_data = array_merge($posted_data, array( 'cf7-serial-number-5' => $serial_number ) ); return $posted_data; }Example-2
// Just replacing Values
add_filter( 'wpcf7_posted_data', 'replace_checkbox_values', 10, 1 ); function replace_checkbox_values( $posted_data ) { $checkbox_value = $posted_data['checkbox-500']; unset( $posted_data['checkbox-500'] ); // posted data for checkbox is in array and as only single value than pass the index. if( $checkbox_value[0] === "Checked" ) { $posted_data = array_merge($posted_data, array( 'checkbox-500' => 'checked' ) ); } else { $posted_data = array_merge($posted_data, array( 'checkbox-500' => 'unchecked' ) ); } return $posted_data; }