dongqiang8683 2019-01-11 07:53
浏览 52

Wordpress子主题ajax调用函数不运行

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。
    • ¥15 livecharts wpf piechart 属性
    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了