• Resolved jaspash

    (@jaspash)


    I need to send Woocommerce data to an external application. This application has “Web Services”.

    I guess that the first step is to activate the “Woocommerce API REST”. Am I right?

    After that my question is: Can I use the available woocommerce hooks to get and send data to this external application?

    Is there any step by step tutorial to learn about this?

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • shaunek

    (@shaunek)

    Likely some more detail about the application you want to integrate with in order to answer your question fully.

    For example, is the application already fully integrated to *pull* data from Woocommerce? Meaning is the application knowledgable about Woocommerce such that it knows how to interact with and pull data from the Woocommerce REST API? If so then yes, generate API credentials for the app and configure it to pull data from your Woocommerce.

    However, if the application has it’s own web service (API) that you are expected to *push* data to then you’ll probably want to:

    1. Search to see if a Woocommerce plugin/extension already exists to push data to said application.
    2. If an existing plugin doesn’t exist you’ll likely need to do some custom development. Engage with a developer who is experienced with Woo who can figure out how to hook into Woocommerce to send data to the web service.
    Thread Starter jaspash

    (@jaspash)

    @shaunek Thanks for your answer.

    The application has it’s own web service (API) and there is no plugin available to pull and push data between the App and Woo.

    As you said, I will need to do custom development. I have some knowledge but I need a starting poing, some tutorial to start.

    Thread Starter jaspash

    (@jaspash)

    My idea is to access the ‘web service’ via https (or http) and then use?wp_remote_post() or?wp_remote_get()? to pull and push data.

    • This reply was modified 2 years ago by jaspash.
    seank123

    (@seank123)

    I used n8n to do something similar (add orders to a Trello board).

    You can set it up to respond if WooCommerce does something: https://n8n.io/integrations/woocommerce-trigger/

    Or you can get/post data to and from WooCommerce: https://n8n.io/integrations/woocommerce/

    Other services are available too: Zapier, Make etc as well as WordPress specific plugins:

    I chose n8n because it can be self hosted (we use a basic Digital Ocean droplet to run it) – they also do a desktop version for Windows and Mac that you can use to test it.

    Thread Starter jaspash

    (@jaspash)

    Thanks @seank123 but I want to do this using my own custom code. I just need to send (push) two valued every time a new order is generated and get back (pull) the stock for the products in the order.

    My idea is to use a HOOK to access the ‘web service’ via https (or http) and then use?wp_remote_post() or?wp_remote_get()? to pull and push data.

    shaunek

    (@shaunek)

    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.
    Thread Starter jaspash

    (@jaspash)

    Hello @shaunek,

    Thank you very much for your very well explained comment. The vendor doesn’t offer a PHP wrapper and the calls are done via HTTPs requests sending/getting XML strings.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Send Woocommerce data to external application with “Web Services”’ is closed to new replies.