简体   繁体   English

在 woocommerce_new_order 钩子内编写的 Javascript 不工作在 function.php 中

[英]Javascript not working written inside woocommerce woocommerce_new_order hook inside function.php

I want to call this hook to trigger just before reviewing the order in checkout.我想在结账时查看订单之前调用这个钩子来触发。 But the ajax response show me the same script code as below and nothing in console box, or any javascript function call made from that hook function not working.但是 ajax 响应向我显示了与下面相同的脚本代码,控制台框中没有任何内容,或者从该钩子函数调用的任何 javascript 函数都不起作用。

add_action( 'woocommerce_new_order', 'wc_send_order_to_mypage' ,10 , 1 );
function wc_send_order_to_mypage($order_id) {
    $order = wc_get_order( $order_id );
    $orderId =  $order->get_id();
    ?>
    <script type="text/javascript">
        console.log('<?php echo $orderId; ?>');
    </script>
    <?php
}

With that hook you can't write on the page.有了这个钩子,你就不能在页面上写字了。 If you want to write on the page you have to use a filter.如果要在页面上书写,则必须使用过滤器。 If you want to write on the page you have to use something else: woocommerce_thankyou_order_received_text woocommerce_checkout_after_order_review Or check the list of hooks or filters hook-docs如果你想在页面上写你必须使用别的东西: woocommerce_thankyou_order_received_text woocommerce_checkout_after_order_review或者检查钩子或过滤器的列表hook-docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM