Title: Run script after purchase
Last modified: August 24, 2016

---

# Run script after purchase

 *  [streamworksaudio](https://wordpress.org/support/users/streamworksaudio/)
 * (@streamworksaudio)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/run-script-after-purchase/)
 * I am going to be selling some software on our site which requires a serial number
   to activate the software. The serial number comes from a 3rd party service. With
   this service I can either manually acquire the serial number and email it to 
   the customer, but preferably I would like to use the services APIs to connect
   to and retrieve the serial number then send it in a separate email (or maybe 
   even add it to their account page).
 * What is the best way to run a 3rd party API when an order completes? And make
   this even more complex, I need to be able to set this per product, as some products
   do not require to connect to this 3rd part service.
 * Thoughts?
 * Cheers
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/run-script-after-purchase/#post-6011047)
 * Have a look at this demo of the woocommerce_thankyou hook as a framework for 
   you to insert your own code to get the serial number and send the email relevant
   for each product:
    [http://pastebin.com/zWuXPXfD](http://pastebin.com/zWuXPXfD)
 *  Thread Starter [streamworksaudio](https://wordpress.org/support/users/streamworksaudio/)
 * (@streamworksaudio)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/run-script-after-purchase/#post-6011065)
 * I will have to look into the woocommerce_thankyou hook!
 * Thanks
 *  Thread Starter [streamworksaudio](https://wordpress.org/support/users/streamworksaudio/)
 * (@streamworksaudio)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/run-script-after-purchase/#post-6011079)
 * I see with your example code you go through each item on the order and put it’s
   meta data into an array. Would this include custom attributes? As I would need
   to have some info for the item that is needed in order to call and get the correct
   serial from the API.
 * In other words, could I set a custom attribute to be like ‘service_product’ and
   set the value to a custom id, then when I make the API call it could be [http://api-url.com?product-id=%5Bcustom](http://api-url.com?product-id=%5Bcustom)
   id from attribute service_product]?
 * If that makes sense 😉
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/run-script-after-purchase/#post-6011090)
 * I don’t know, I would use `var_dump($item);` to see what fields are present.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Run script after purchase’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/run-script-after-purchase/#post-6011090)
 * Status: not resolved