-
-
Save gamalkamal/80134c655fdc322bd751d1b0ed0f7336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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