Plugin Support
RK a11n
(@riaanknoetze)
Hi there,
This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.
You can also visit the WooCommerce Facebook group or the #developers
channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.
Thanks for the heads-up RK, i am already trying on slack woocommerce community as well.
I’ll keep up to date on this one as well to see if someone is able to help me.
Hello @horizont ,
While you are getting a reply from the Slack WooCommerce Community, I would like to share my 2 cents on the topic which I found interesting.
Here is my approach to getting all the possible variations name under a product –
global $product;
$variations = $product->get_available_variations();
$variations_ids = wp_list_pluck( $variations, 'variation_id' );
foreach ($variations_ids as $variations_id) {
$variation = wc_get_product($variations_id);
echo __("<li>" . $variation->get_name() ."</li>");
}
I hope this will help you to get more ideas.
Thank you 🙂
Hey @rur165.
Thanks for your contribution. As i am flooded with other requests i’ll try it as soon as i can and get back at you 🙂
Thanks again for your help, much appreciated 🙂
If I am not mistaken you get all the variations ids specifically for a product because with those you can go back to the product details themselves and pick the “display” name from there.
Which is fine.
I actually needed to include only the
$variation = wc_get_product($variations_id);
echo __("<li>" . $variation->get_name() ."</li>");
part because i obviously already had a foreach cycle and var ids in place to build my workaround with them anyways.
Problem is, the name is the full name, which is “Product name – Variation name” so i will have to strip the product name anyways if I only want the Variation Name.
Anyways, it certainly is better than my workaround because it relies on me adding the Variation name also in the Description field which isn’t ideal or even conceptually right.
Am i correct with this?
Hello @horizont ,
The code I have shared is for suggestion only. It does not matter how you get access to the variation ID as long as you get it right.
Apart from the above method, I could not get a direct way to get variations. Also, I am not fully sure about the term variation name because those are actually attributed under each variation which you can get following this example – https://stackoverflow.com/a/42998914.
I hope you will be able to modify the use case as per your need.
Thank you 🙂
Hi @horizont,
This thread has been inactive for a while, so I’ll be marking it as resolved. Hopefully, the info shared above was helpful!
If you have further questions, please feel free to open a new topic.
Thanks.