Send data via API after a WooCommerce sale

55 Views Asked by At

I am pretty new to API's and can't figure this out! I have courses on Moodle which I sell via Wordpress / Woocommerce. Upon a successful sale I need to automatically enrol the user to Moodle. To do this I have been given a post URL and data fields in JSON. The link looks like this:

https://XXXX.co.uk/webservice/restful/server.php/XXXX_woo_commerce?moodlewsrestformat=json

And this is the body text I need to send to it:

{
    "users": [
        {
            "email": XXXX,
            "firstname": "test",
            "lastname": "user",
            "courseid": "2",
            "address1": "address line 1",
            "address2": "address line 1",
            "addresscity": "city",
            "addresspostcode": XXXX,
            "addresscounty": XXXX,
            "addresscountry": "GBR",
            "dob": "20200629"
        }
    ]
}

I have no idea to integrate this into a function. I have created a plugin to get the data I need and I have the my_order_complete_function( $order_id ) function ready - I just have no clue how to then instruct it to send the body JSON data to the URL.

Any help would be greatly appreciated.

0

There are 0 best solutions below