Title: Get Variable Name?
Last modified: August 30, 2016

---

# Get Variable Name?

 *  [AustinTBiggs](https://wordpress.org/support/users/austintbiggs/)
 * (@austintbiggs)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/get-variable-name/)
 * Hello,
 * I’ve created a custom page, that adds an item variation to the cart when a product
   id and variation id are supplied. However I’m finding it impossible to retrieve
   the name of the variation for use in a success message.
 * “VARIATION NAME has been added to the cart!”
 * Does anybody know how to achieve this? What I’m referring to as the VARIABLE 
   NAME is the text that is in the dropdown on the product page for the add to cart
   button..
 * Any direction or help is greatly appreciated!
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

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

 *  [Matt Cohen](https://wordpress.org/support/users/mattyza/)
 * (@mattyza)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/get-variable-name/#post-6468484)
 * Hi Austin,
 * > I’ve created a custom page, that adds an item variation to the cart when a 
   > product id and variation id are supplied. However I’m finding it impossible
   > to retrieve the name of the variation for use in a success message.
 * As you have the product ID present, I’d say a good starting point would be to
   sanitise this value (make sure it’s an integer), and then instantiate a `$product_to_use
   = new WC_Product( $product_id );`.
 * From there, you can `var_dump()` on `$product_to_use` and see the various properties
   available to you.
 * I hope this helps as a starting point. 🙂
 *  Thread Starter [AustinTBiggs](https://wordpress.org/support/users/austintbiggs/)
 * (@austintbiggs)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/get-variable-name/#post-6468485)
 * Thank you Matt, I’ll give this a try and post back!

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

The topic ‘Get Variable Name?’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [AustinTBiggs](https://wordpress.org/support/users/austintbiggs/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/get-variable-name/#post-6468485)
 * Status: not resolved