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 '+')
As opposed to simple products, WooCommerce lets you create products with variations. For example, you might have seen shops with shirts of different sizes and colors or items with different designs and decals. Each of those combinations is a different variation. So variable products are products that have variations based on attributes.
WooCommerce helps you to add multiple variations to your products. Displaying variations and attributes for your online products helps the customers to get a detailed overview of items they would like to purchase. On the other hand, it can help you increase sales, overall revenue, and brand loyalty among your customers.
While WooCommerce gives you the ability to already do product variations and product filters, a plugin for WooCommerce for swatches, for instance, will add functionality. This includes things like how items look via images, labels, color swatches, and radio buttons.
These will be the product variations that appear on your site’s front-end. Go to the Variations tab, use the dropdown to select the Add variation option, and click on the Go button. Select whichever attribute values apply to the product.
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:
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.
I think many will search for a solution to link specific variations by a url parameter so here is a longer answer for that topic.
As many others mentioned here, you can access any variation with the attribute parameter. The way you choose an variation on the product details page is an select menu. The name attribute of that select is the parameter name and the options value attribute is the parameter value. Here is an example:
If you want to link the highlighted variation your link will be like https://example.com/some_product/?attribute_pa_size=small
Of course you can add multiple parameters like https://example.com/some_product/?attribute_pa_size=small&attribute_pa_color=red
The thing is, using dev tools to dig out these informations is not a very convenient solution. Down below is a code snippet you can add to your themes functions.php (or inside a simple one-file-plugin) that shows a variation-permalink in the wordpress admin of the specific product variation tab/accordeon.
add_action( 'woocommerce_product_after_variable_attributes', 'gdy_add_wc_varition_permalink', 100, 3 );
function gdy_add_wc_varition_permalink( $loop, $variation_data, $variation ) {
echo '<a href="' . get_permalink( $variation->ID ) . '" target="_blank">' . __( 'Permalink for this variation' ) . '</a>';
}
I have tried so many solutions and plugins myself, but i found a way to easily do it without a plugin. I'm not sure if this worked back in oktober 2015, but it does work now.
I have explained it in this youtube video https://www.youtube.com/watch?v=Y_hMI4bXN6A
What you want to do is add something like '/?attribute_color=red' behind your product.
website.com/shop/product1/?attribute_color=red
website.com/shop/product1/?attribute_length=10m
However what i found out by trial and error is what matters is the type of attribute you use. You can add a attribute in 2 ways, a pre-made one (text/select) or a custom attribute. Linking directly with this method only works if you create a custom product attribute.
For it to work you have to pay attention if you used capitol letters or not. For the name of the custom product attribute it wont matter if you use capitols in the backend (as long as you dont use theme in the url). For the values however you can only use normal letters and no capitols, both in the backend as in the url itself.
Example
Name: Color
Values: red | Black, green
website.com/shop/product1/?attribute_color=red > will work
website.com/shop/product1/?attribute_Color=red > will not work
website.com/shop/product1/?attribute_color=Red > will not work
website.com/shop/product1/?attribute_color=Black > will work
website.com/shop/product1/?attribute_color=black > will not work
I have explained it in this youtube video https://www.youtube.com/watch?v=Y_hMI4bXN6A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With