I have a wordpress installation with theme: Escapium and i using its own child theme. I have added functions.php into the child theme directory. Within that i try to make an ajax call for a function inside the functions.php but that function is just not run whatever i do. Ajax response is: 1
add_action( 'wp_footer', 'checkout_place_order_script' );
add_action( 'wp_ajax_send_email', 'send_email' );
add_action( 'wp_ajax_nopriv_send_email', 'send_email' );
function checkout_place_order_script() {
// Only checkout page
if( is_checkout() && ! is_wc_endpoint_url() ):
// jQuery code start below
?>
<script src="https://unpkg.com/sweetalert2@7.20.1/dist/sweetalert2.all.js"></script>
<script type="text/javascript">
jQuery( function($){
var fc = 'form.checkout',
pl = 'a[name="woocommerce_checkout_place_order"]';
$(fc).on( 'click', pl, function(e){
<?php
$six_digit_random_number = mt_rand(100000, 999999);
?>
e.preventDefault(); // Disable "Place Order" button
// Sweet alert 2
swal({
title: '111',
text: "You are about proceed the order",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: "Yes let's go!"
}).then((result) => {
if (result.value) {
console.log(result);
//$(fc).off(); // Enable back "Place Order button
//$(pl).trigger('click'); // Trigger submit
$.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: "POST",
cache: false,
data:{
action: 'send_email',
code: '<?php $six_digit_random_number ?>',
},
});
} else {
$('body').trigger('update_checkout'); // Refresh "Checkout review"
}
});
});
});
</script>
<?php
endif;
}
function send_email(){
$to = 'test@mail.mail';
$subject = 'Verification Code';
$message = '123456';
wp_mail( $to, $subject, $message );
wp_die();
}
I don't know what's wrong with this, as it should works like this i guess?!