Confused By Choices

Deep Linking Product Variants in WooCommerce

Trey Ecommerce, Technical, WooCommerce, Wordpress

WooCommerce has a lot of hidden little features. One seemingly undocumented feature is the ability to create deep links into product variations.

The idea is simple, you want to provide people with a link directly to a preconfigured variable product. This makes things so much easier when sharing links than having to direct the user which options to select when there’s a wide array of options.

Pro-Tip: WooCommerce uses these links in the cart page (specifically the list of products in your cart), one very rapid way of generating these links is to add the product in question to your cart, then copy the link from there.

To illustrate how you can generate one of these deep linked URLs for yourself we’ll look at an example. Let’s say that we’ve setup an attributed product called “Cool Sunglasses”, and that these sunglasses we have setup are located at https://example.com/product/cool-sunglasses/.

Because we’re a sunglass company, we have some product attributes throughout our store (these are added via the Products->Attributes in the WordPress Dashboard, setting up said attributes is outside of the scope of this article). These common attributes are “Lens Tint” and “Prescription Lens”. Our “Cool Sunglasses” product also contain a custom attribute specific to them called “Frame Color”.

What you have to understand is these so called product attributes are treated differently when we build our URL than the aforementioned custom attribute. The product attributes slugs are prefixed with pa_ whereas the custom attributes are not. So in our example a final URL might be https://example.com/product/cool-sunglasses/?attribute_frame-color=Lime&attribute_pa_prescription-lens=premium-rx&attribute_pa_lens-tint=amber. So, let’s break this down we have BASE_URL?attribute_[pa_]slug=selected_attribute.

To recap, it’s completely possible to deep link to a specific variation when using variable products in WooCommerce. Building the URL manually can get a bit tedious, and there’s a few gotchas (looking at you pa_ prefix), but once you get the hang of it you and those you’re sending these links to will be grateful.

Designed by Freepik