Woocommerce - How To Link to Product Variation?

MrMo picture MrMo · Oct 18, 2015 · Viewed 25.6k times · Source

I am trying to find a way to have a link to a specific product variation.

I thought I had it solved with this plugin... https://wordpress.org/plugins/woocommerce-direct-variation-link/

However the I have 2 word product attribute names and can't seem to get it to work? I put _, -, & and + between the 2 words but not go.

Here is the doc...In my case I would have "color style" instead of just "color" mysite.com/product/happy-ninja/?color=blue

mysite.com/product/happy-ninja/?color=blue&size=small (additional variations should be separated by '&')

mysite.com/product/happy-ninja/?color=blue+green (where the variation value is "Blue Green" with the space replaced by a '+')

Answer

Ashwin Anandani picture Ashwin Anandani · Apr 19, 2018

Further to the last poster, I couldn't get his code to work properly, but I did discover that WooCommerce generates these for the Cart most of the time:

  1. Visit a variation product yourself
  2. Add a variation to the Cart
  3. Open your cart and hover over the item --> the link in your status bar (or right click > Copy Link Address) is it!

It should have a suffix like this: http://website.com/product/product-name/?attribute_colours=Grey

Note that colours is lowercase because it's the slug while Grey is the actual name for the Variation.

For spaces in your Variation name, use a + instead of the space.

For selecting multiple variation attributes, I believe you can just start with & and spit the ?attribute_[slug]=Variation again.