Yeah, @jaspash I think you are on the right track. I’m sorry I can’t point you to a specific tutorial but I’m sure googling you will come across a few articles and you’ll be able to piece together what you need.
A few things I can suggest as a starting point…
The idea of using wp_remote_post/get() is likely a good idea. But before honing in on that I might recommend checking if this vendor provides some sort of PHP SDK. Your vendor calls their API “web services” so almost certainly it is an HTTP-based API using JSON or XML, which is great, but many vendors also provide a library that is a simple wrapper around their raw HTTP API. These SDK libraries can be more convenient and safer to work with if done well. As an example, Stripe has HTTP-based APIs but they provide a PHP SDK that just makes it way easier to program with when comparing with using the raw underlying HTTP-based API: https://stripe.com/docs/api?lang=php.
If your vendor doesn’t offer a PHP wrapper, then most likely your hunch to use wp_remote_post() or wp_remote_get() is correct. Of course every API is different so nobody will be able to give specific details beyond this point. You’ll need to 1) learn how to use wp_remote_post/get() (like maybe this one I found by searching “how to use wp_remote_get”) and then 2) study their API docs. There will be some sort of authentication method they’ll require which may be one of dozens of common auth methods, and then of course learning what the sending and receiving payload should be as well as the different error conditions. You’ll need to figure that out yourself, really no tutorial can tell you that, unless your vendor has a tutorial in their docs.
If you are looking to make the API calls after each order I might recommend using the “woocommerce_checkout_order_processed” hook or the “woocommerce_new_order” hook. The former will run for orders placed by the customer after checkout, but later will run for checkout and admin orders. If you use the woocommerce_new_order hook this SO post has the relevant info on how to get both the order_id and the full order https://stackoverflow.com/a/66813346/156699.
Good luck
-
This reply was modified 2 years ago by
shaunek.