Skip to content

Instantly share code, notes, and snippets.

@vicctim
Created June 27, 2023 19:35
Show Gist options
  • Save vicctim/f02ad77b4338b627db075bc8a3764571 to your computer and use it in GitHub Desktop.
Save vicctim/f02ad77b4338b627db075bc8a3764571 to your computer and use it in GitHub Desktop.
[WordPress] Formulário de contato Elementor e Piotnet com envio de API WhatsApp
<?
add_filter('pafe/form_builder/custom_message', 'piotnet_check_code', 10, 4);
function piotnet_check_code($bool, $form_submission, $remote_request_response, $webhook_response) {
// Only run this filter for Code submit form
$form_id = $form_submission['form']['id'];
if ($form_id != 'atendimento2') {
return null;
}
// Get code value from Form
$fields = $form_submission['fields'];
$field_id = 'nome';
$nome = $fields[$field_id]['value'];
$field_id = 'email';
$email = $fields[$field_id]['value'];
$field_id = 'whatsapp';
$whatsapp = $fields[$field_id]['value'];
$field_id = 'periodo';
$periodo = $fields[$field_id]['value'];
$field_id = 'profissional';
$profissional = $fields[$field_id]['value'];
$mensagem = "Solicitação de consulta via site "
. "\n\n"
. "📝 *Nome:* "
. $nome
. "\n"
. "📱 *Telefone:* "
. $whatsapp
. "\n"
. "📧 *E-mail:* "
. $email
. "\n"
. "🕒 *Período:* "
. $periodo
. "\n"
. "🩺 *Profissional:* "
. $profissional
;
$url = 'http://x.x.x.X:PORTA/zdg-message';
$telefoneapi ="5534xxxxxxxxx";
$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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment