John Davidson

php - No hook for new order on woocommerce in a plugin

0 comments
Message:


I tried about 5 hooks to get the order hook for completed and the function doesn't run at all but woocommerce_add_to_cart for example is working!


1. woocommerce_order_status_changed

2. woocommerce_new_order


I just make the alert to know if the function runs but the fucntion is quite large and I make order manullay as a test before deploying the plugin in this function in the plugin in index.php


    function SP_order_token($order_id)
{


?>
<script>
alert("hello");
alert('<?php echo $order_id; ?>');
</script>
<?php
echo "hello";

global $woocommerce, $post;


echo $order_id;

$order = wc_get_order($order_id);

$order_data = $order->get_data(); // The Order data

var_dump($order_data);
}
// the final hook is when an order successfully paid
add_action('woocommerce_order_status_changed', 'SP_order_token',10,1);


My Answer:
3. woocommerce_checkout_order_processed

4. woocommerce_payment_complete

5. woocommerce_thankyou

You can try using one of these hooks instead of the ones you have already tried. Make sure to check the documentation for each hook to see if it fits your requirements for when you want the function to run.

Rate this post

4 of 5 based on 5034 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us