Skip to content

WooCommerce – Programmatically get Variation Title by Variation product_Id

I was building a custom form for my client where I wanted to create a shortcode that generates a button where a user could add a Subscription to their cart.

Each subscription product has a number of variations. Variations are stored as posts but meta information is stored as if they are product options.

If you try to retrieve the post_title of a variation by its ID, it will display something like the following.

Variation #0000 of Some Product

Here is how to retrieve the product option title rather than the variation post title.

// Assuming you already have $variation_id set
get_post_meta($variation_id, 'attribute_options');

Returns an array

    [attribute_options] => Array
    (
        [0] => Some Variation Title
    )

With thanks http://stackoverflow.com/questions/29741270/woocommerce-get-product-variation-title/33495560#33495560

About 

10 years + experience in web development working with lots of different technology.

Published inWooCommerceWordPress

One Comment

  1. john john

    no, I think the best you can do here is the slug

Leave a Reply

Your email address will not be published. Required fields are marked *