Wordpress child theme ajax call for functions doesn't run

42
January 12, 2019, at 10:10 AM

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?!

READ ALSO
Unable to insert to multiple table rows to oracle(10g) database using for loop PHP

Unable to insert to multiple table rows to oracle(10g) database using for loop PHP

Unable to insert the multiple rows in the database while using the for loop, instead of inserting the multiple rows it will insert only the single row to the oracle DB

44
Custom queries using arrays and implode function in php

Custom queries using arrays and implode function in php

I am coding a game siteOn this site, every question should be displayed to the user only once

36
look for a tool to consume redis and virsialize the process

look for a tool to consume redis and virsialize the process

I am looking for a open source software to configure php scripts to consume redis list,and visualize the whole process and monitor the whole process

21
How to catch an exception for sodium_crypto_box

How to catch an exception for sodium_crypto_box

I am trying to see if the message gets corrupted in the middle I should be able to get an error but all I am seeing is a white page

7