-
-
Save dexit/bae98c0c6842cfa6a07af21feb8632c3 to your computer and use it in GitHub Desktop.
[WordPress] Formulário de contato Elementor com envio de API WhatsApp
This file contains hidden or 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
<? add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) { | |
//Setar o form_name | |
$form_name = $record->get_form_settings( 'form_name' ); | |
//Definir o formulário | |
if ( 'contato' !== $form_name ) { | |
return; | |
} | |
//Buscar os campos do formulário | |
$raw_fields = $record->get( 'fields' ); | |
$fields = []; | |
foreach ( $raw_fields as $id => $field ) { | |
$fields[ $id ] = $field['value']; | |
} | |
//Definir as variáveis de acordo com a ID | |
$nome = $fields['nome']; | |
$email = $fields['email']; | |
$whatsapp = $fields['whatsapp']; | |
$mensagem = $fields['mensagem']; | |
$mensagem = "Formulário de contato em site" | |
. "\n\n" | |
. "*Nome*: " | |
. $fields['nome'] | |
. "\n" | |
. "*Telefone*: " | |
. $fields['whatsapp'] | |
. "\n" | |
. "*E-mail*: " | |
. $fields['email'] | |
. "\n" | |
. "*Mensagem*: " | |
. $fields['mensagem'] | |
; | |
//Setar o disparo da mensagem | |
$url = 'http://x.x.x.x:PORTA/zdg-message'; | |
$telefoneapi ="5534xxxxxxxxx"; | |
//dispara a mensagem da API para o cliente | |
$data = array('number' => $telefoneapi, 'message' => $mensagem); | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data) | |
) | |
); | |
// Enviar | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment