Created
December 6, 2023 16:38
-
-
Save dantetesta/3cd1ceca1cda2d634db432c28f58afa1 to your computer and use it in GitHub Desktop.
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
// Adicionar coluna personalizada | |
add_filter('manage_pedidos_posts_columns', function ($columns) { | |
$columns['reenviar_email'] = 'Reenviar por E-mail'; | |
return $columns; | |
}); | |
// Exibir conteúdo na coluna personalizada | |
add_action('manage_pedidos_posts_custom_column', function ($column, $post_id) { | |
if ($column == 'reenviar_email') { | |
echo '<a href="#" class="reenviar-email" data-post-id="' . $post_id . '">Reenviar</a>'; | |
} | |
}, 10, 2); | |
// Adicionar scripts no admin | |
add_action('admin_footer', function () { | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function ($) { | |
$('.reenviar-email').on('click', function (e) { | |
e.preventDefault(); | |
var postId = $(this).data('post-id'); | |
$.ajax({ | |
url: ajaxurl, | |
type: 'POST', | |
data: { | |
action: 'reenviar_email', | |
post_id: postId, | |
}, | |
success: function (response) { | |
alert('E-mail reenviado com sucesso!'); | |
}, | |
error: function () { | |
alert('Erro ao reenviar e-mail.'); | |
} | |
}); | |
}); | |
}); | |
</script> | |
<?php | |
}); | |
// Manipular solicitação AJAX | |
add_action('wp_ajax_reenviar_email', function () { | |
$post_id = $_POST['post_id']; | |
$post = get_post($post_id); | |
$email = get_post_meta($post_id, '_email', true); | |
$whatsapp = get_post_meta($post_id, '_whatsapp', true); | |
$obs = get_post_meta($post_id, '_obs', true); | |
$produtos = get_post_meta($post_id, '_produtos', true); | |
$receiver = get_option('tema-config')['_receiver']; | |
$subject = "Detalhes do Pedido: {$post->post_title}"; | |
$message = "Olá {$post->post_title}, <br><br>"; | |
$message .= "<h2>Detalhes do Orçamento</h2>"; | |
$message .= "E-mail do Cliente: {$email}<br>"; | |
$message .= "Whatsapp do Cliente: {$whatsapp}<br><br>"; | |
$message .= "Observações: {$obs}<br><br>"; | |
$message .= "<h2>Itens do Orçamento</h2>"; | |
$message .= $produtos; | |
$headers = ['Content-Type: text/html; charset=UTF-8']; | |
wp_mail($receiver, $subject, $message, $headers); | |
//wp_mail($email, $subject, $message, $headers); | |
wp_die(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment