简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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