INTEGRAÇÃO COM ELEMENTOR
'',
'mensagem' => 'Mensagem para o comercial',
'nome' => 'João'
),
array(
'telefone' => '',
'mensagem' => 'Mensagem para o Cliente',
'nome' => 'Maria'
)
);
foreach($dados as $key => $v){
}
*/
// NÃO HÁ NECESSIDADE DE ALTERAR A NÃO SER QUE VOCê PRECISE CUSTOMIZAR DA SUA FORMA
function valida_telefone_whatsapp($telefone)
{
$telefone = preg_replace("/\D/", "", $telefone);
$ddd = substr($telefone, 0, 2);
// Se for São Paulo e Rio de Janeiro, vamos Manter o Digito 9 Adicional. Caso contrário vamos remover 1 Dígito 9.
if ($ddd === "11" || $ddd === "12" || $ddd === "13" || $ddd === "14" || $ddd === "15" || $ddd === "16" || $ddd === "17" || $ddd === "18" || $ddd === "19" || $ddd === "21" || $ddd === "22" || $ddd === "24" || $ddd === "27" || $ddd === "28") {
$telefone = $telefone;
} else {
$telefone = substr($telefone, -8); //96320544
$telefone = $ddd . $telefone; //3196320544
$telefone = $telefone;
}
return $telefone;
}
// Todo código deverá ser inserido no functons do seu tema filho
// Ou se vocÊ tiver conhecimentos poderá criar um plugin para isso.
// A send custom WebHook
add_action('elementor_pro/forms/new_record', function ($record, $handler) {
//make sure its our form
$form_name = $record->get_form_settings('form1');
// Replace MY_FORM_NAME with the name you gave your form
if ($FormNameElementor !== $form_name) {
return;
}
$raw_fields = $record->get('fields');
$fields = [];
$telefone = array();
foreach ($raw_fields as $id => $field) {
$fields[ $id ] = $field['value'];
}
// Telefone que a API irá enviar.
$telefone = valida_telefone_whatsapp($fields['telefone']);
// Alterar conforme sua necessidade
$mensagem = "Mensagem enviada pelo formulário do Elementor" . $fields['nome'];
$data = array('sender' => 'primary', 'number' => '+55' . $telefone, 'message' => $mensagem);
$curl = curl_init();
$url_ip = "http://116.203.60.247:9000/send-message/";
curl_setopt_array($curl, array(
CURLOPT_URL => $url_ip,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'content-type: application/x-www-form-urlencoded',
),
));
// Envia a requisição e salva a resposta
$response = curl_exec($curl);
$resposta = json_decode($response);
if ($resposta->status == 1) { // 1 = OK
$resp = "numero_valido";
echo $resp;
} elseif ($resposta->status == "" or $resposta->status == null) {
$resp = "numero_invalido";
echo $resp;
}
}, 10, 2);
?>
INTEGRAÇÃO JET-APPOIMENT
'primary', 'number' => '+55' . $telefone, 'message' => $mensagem);
$curl = curl_init();
$url_ip = "http://116.203.60.227:9001/send-message/";
curl_setopt_array($curl, array(
CURLOPT_URL => $url_ip,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'content-type: application/x-www-form-urlencoded',
),
));
// Envia a requisição e salva a resposta
$response = curl_exec($curl);
$resposta = json_decode($response);
if ($resposta->status == 1) { // 1 = OK
$resp = "numero_valido";
echo $resp;
} elseif ($resposta->status == "" or $resposta->status == null) {
$resp = "numero_invalido";
echo $resp;
}
}
);
function data_agendamento($data){
// Tratando as datas No banco do jet apointiment
global $wpdb;
//$id_agendamento = $data[0]['post_id'];
$id_agendamento = $data['appointment_id_list'][0];
$result = $wpdb->get_results ( "SELECT * FROM {$wpdb->prefix}jet_appointments WHERE ID = $id_agendamento ",ARRAY_A );
$data_dia = date('d/m/Y', $result[0]['date']);
$data_hi = date('H:i', $result[0]['slot']);
$data_hs = date('H:i', $result[0]['slot_end']);
return $data_dia;
}
function horario_inicial($data)
{
// Tratando as datas No banco do jet apointiment
global $wpdb;
//$id_agendamento = $data[0]['post_id'];
$id_agendamento = $data['appointment_id_list'][0];
$result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}jet_appointments WHERE ID = $id_agendamento ", ARRAY_A);
$data_dia = date('d/m/Y', $result[0]['date']);
$data_hi = date('H:i', $result[0]['slot']);
$data_hs = date('H:i', $result[0]['slot_end']);
return $data_hi;
}
function horario_final($data)
{
// Tratando as datas No banco do jet apointiment
global $wpdb;
//$id_agendamento = $data[0]['post_id'];
$id_agendamento = $data['appointment_id_list'][0];
$result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}jet_appointments WHERE ID = $id_agendamento ", ARRAY_A);
$data_dia = date('d/m/Y', $result[0]['date']);
$data_hi = date('H:i', $result[0]['slot']);
$data_hs = date('H:i', $result[0]['slot_end']);
return $data_hs;
}
function get_nome_profissional($data,$slug_post_type_profissional){
// Tratando as datas No banco do jet apointiment
global $wpdb;
//$id_agendamento = $data[0]['post_id'];
$id_agendamento = $data['appointment_id_list'][0];
$result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}jet_appointments WHERE ID = $id_agendamento ", ARRAY_A);
$query_args = array(
'post_type' => $slug_post_type_profissional,
'post_status' => 'publish',
'post__in' => array($result[0]['provider']),
'posts_per_page' => '1',
);
$result = get_posts($query_args);
$nome = $result[0]->post_title;
return $nome;
}
function get_nome_servico($data,$slug_post_type_servico){
global $wpdb;
//$id_agendamento = $data[0]['post_id'];
$id_agendamento = $data['appointment_id_list'][0];
$result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}jet_appointments WHERE ID = $id_agendamento ", ARRAY_A);
$query_args = array(
'post_type' => $slug_post_type_servico,
'post_status' => 'publish',
'post__in' => array($result[0]['service']),
'posts_per_page' => '1',
);
$result = get_posts($query_args);
$nome = $result[0]->post_title;
return $nome;
}
?>
INTEGRAÇÃO JET-FORMS
'primary', 'number' => '+55' . $telefone, 'message' => $mensagem);
$curl = curl_init();
$url_ip = "http://116.203.60.242:9001/send-message/";
curl_setopt_array($curl, array(
CURLOPT_URL => $url_ip,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'content-type: application/x-www-form-urlencoded',
),
));
// Envia a requisição e salva a resposta
$response = curl_exec($curl);
$resposta = json_decode($response);
if ($resposta->status == 1) { // 1 = OK
$resp = "numero_valido";
echo $resp;
} elseif ($resposta->status == "" or $resposta->status == null) {
$resp = "numero_invalido";
echo $resp;
}
}
);
?>
INTEGRAÇÃO WOOCOMMERCE
has_status('processing')) {
$msgGeneric = "Mensagem Personalizada que você irá enviar";
} elseif ($order->has_status('completed')) {
$msgGeneric = "Mensagem Personalizada que você irá enviar";
} elseif ($order->has_status('failed')) {
$msgGeneric = "Mensagem Personalizada que você irá enviar";
} elseif ($order->has_status('on-hold') or $order->has_status('pending')) {
$msgGeneric = "Mensagem Personalizada que você irá enviar";
} elseif ($order->has_status('cancelled')) {
$msgGeneric = "Mensagem Personalizada que você irá enviar";
$msgGeneric = "Mensagem Personalizada que você irá enviar";
} elseif ($order->has_status('refunded')) {
$msgGeneric = "Mensagem Personalizada que você irá enviar";
}else{
}
$envia_img = "nao";
$UrlImagem = "";
$cap = "";
$order_number = $order->get_order_number();
$order_date = date('Y-m-d H:i:s', strtotime(get_post($order->get_id())->post_date));
$order_total = wc_format_decimal($order->get_total(), 2);
$payment_method = $order->get_payment_method();
$shipping_method = $order->get_shipping_method();
$country = $order->get_billing_country();
switch ($country) {
case 'AR':
$codigo_pais = "54";
break;
case 'BO':
$codigo_pais = "591";
break;
case 'CL':
$codigo_pais = "56";
break;
case 'CO':
$codigo_pais = "57";
break;
case 'BR':
$codigo_pais = "55";
break;
case 'EC':
$codigo_pais = "593";
break;
case 'PE':
$codigo_pais = "51";
break;
case 'VE':
$codigo_pais = "58";
break;
case 'PT':
$codigo_pais = "351";
break;
}
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
$contato_cliente = $order->get_billing_phone();
$billing_state = $order->get_billing_state();
$shipping_address_1 = $order->get_billing_address_1();
$shipping_address_2 = $order->get_billing_address_2();
$endereco_completo = $shipping_address_1 . $shipping_address_2;
$shipping_postcode = $order->get_billing_postcode();
$shipping_city = $order->get_billing_state();
$shipping_state = $order->get_billing_state();
$shipping_country = $order->get_billing_country();
$codigo_rastreio = get_post_meta($order_id, '_correios_tracking_code', 'true');
$lista_produtos = '';
// Get and Loop Over Order Items
foreach ($order->get_items() as $item_id => $item) {
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
$product = $item->get_product();
$product_name = $item->get_name();
$quantity = $item->get_quantity();
$subtotal = $item->get_subtotal();
$total = $item->get_total();
$tax = $item->get_subtotal_tax();
$taxclass = $item->get_tax_class();
$taxstat = $item->get_tax_status();
$allmeta = $item->get_meta_data();
$somemeta = $item->get_meta('_whatever', true);
$product_type = $item->get_type();
$lista_produtos .= 'Produto: ' . $product_name . ' | Quantidade: ' . $quantity . ' | Total: ' . $total . PHP_EOL;
}
if ($contato_cliente != "") {
$mensagem = str_replace(
array('{nome_cliente}', '{sobrenome_cliente}', '{numero_pedido}', '{data_pedido}', '{metodo_pagamento}', '{endereco}', '{codigo_postagem}', '{cidade}', '{estado}', '{pais}', '{total_pedido}', '{lista_itens_comprados}', '{codigo_rastreio}'),
array($billing_first_name, $billing_last_name, $order_number, $order_date, $payment_method, $endereco_completo, $shipping_postcode, $shipping_city, $shipping_state, $shipping_country, $total, $lista_produtos, $codigo_rastreio),
$msgGeneric
);
} else {
$mensagem = "";
}
$telefone = valida_telefone_whatsapp($fields['telefone']);
// Alterar conforme sua necessidade
$mensagem = $mensagem;
$data = array('sender' => 'primary', 'number' => '+55' . $telefone, 'message' => $mensagem);
$curl = curl_init();
$url_ip = "http://116.203.60.247:9001/send-message/";
curl_setopt_array($curl, array(
CURLOPT_URL => $url_ip,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'content-type: application/x-www-form-urlencoded',
),
));
// Envia a requisição e salva a resposta
$response = curl_exec($curl);
$resposta = json_decode($response);
if ($resposta->status == 1) { // 1 = OK
$resp = "numero_valido";
echo $resp;
} elseif ($resposta->status == "" or $resposta->status == null) {
$resp = "numero_invalido";
echo $resp;
}
//write_log($msg);
};
add_action('woocommerce_order_status_changed', 'ninja_woo_api_status_pedido_enviado', 10, 3);
//add_action( 'woocommerce_thankyou', 'ninja_woo_api_status_pedido_enviado', 10, 3);