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);