In WooCommerce, I would like to send a request to an API once the customer has successfully checked out. Its basically a website where the client is selling online courses (Like udemy).
When the customer checks out, I would like to send an API request and enroll the user for that particular course. I have tried several WooCommerce hooks but none worked for me.
This is the code that I'm using:
add_action('woocommerce_checkout_order_processed', 'enroll_student', 10, 1);
function enroll_student($order_id)
{
echo $order_id;
echo "Hooked";
}
I am writing this code for a plugin and to make it easier, I am currently using Cash on Delivery method.
Can anyone point me out where I am going wrong because when I checkout I cant see the message "hooked" that I am printing nor the $order_id
?
It takes me to the success page and doesn't show these two things that I am printing.
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Related thread:
The code is tested and works.
May be you could use
woocommerce_thankyou
hook instead, that will display on order-received page your echoed code, this way:Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and works.
Related: