Skip to content

Instantly share code, notes, and snippets.

@gamalkamal
Forked from yeriepiscesa/snippet-1.php
Created August 5, 2019 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamalkamal/80134c655fdc322bd751d1b0ed0f7336 to your computer and use it in GitHub Desktop.
Save gamalkamal/80134c655fdc322bd751d1b0ed0f7336 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'wpcf7_skip_mail', 'solusiprss_cf7_send_whatsapp', 10, 2 );
add_filter( 'wpcf7_display_message', 'solusipress_cf_wa_sent_message', 10, 2 );
add_action( 'wp_footer', 'solusipress_cf7_add_script_footer' );
function solusiprss_cf7_send_whatsapp( $skip_mail, $contact_form ) {
if( $contact_form->id() == 105 ) {
$skip_mail = true;
}
return $skip_mail;
}
function solusipress_cf_wa_sent_message( $message, $status ) {
if( $status == 'mail_sent_ok' ) {
$message = 'Terima kasih telah mengisi kontak form';
}
return $message;
}
function solusipress_cf7_add_script_footer() {
if( is_page( 'contact-form-whatsapp' ) ):
?><script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
var inputs = event.detail.inputs;
var the_text = '';
jQuery.each( inputs, function( index, detail ) {
if( the_text != '' ) { the_text += "\n"; }
switch( detail.name ) {
case 'your-name':
the_text += "Nama : " + detail.value;
break;
case 'your-email':
the_text += "Email : " + detail.value;
break;
case 'your-subject':
the_text += "Subject : " + detail.value;
break;
case 'your-message':
the_text += "Message : " + detail.value;
break;
}
} );
the_text = window.encodeURIComponent( the_text );
var the_phone = '6281314997198'; // ganti nomor dengan milik Anda
var url = 'https://api.whatsapp.com/send?phone=' + the_phone + '&text=' + the_text;
var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if( isSafari && iOS ) {
location = url;
} else {
window.open( url, '_blank' );
}
}, false );
</script><?php
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment