Dynamic URL’s for product attributes
-
I am wanting to have dynamic URL’s in browser that change with product variations selected. I want to do this so I can send links to customers with a selected product that will display price for selected variation.
The page I need help with: [log in to see the link]
-
I can see you are looking to generate dynamic URLs that reflect the selected variation, so you can share a direct link with customers that preselects the variation and displays the correct price. That makes a lot of sense for improving the buying experience, and I am happy to guide you through it.
WooCommerce already supports linking directly to specific product variations using URL query parameters. When a variation is selected, the URL can include the attribute name and value, for example:
?attribute_pa_color=black&attribute_pa_size=largeTo get this working:
- Make sure your product attributes are used for variations and are set as Global attributes.
- Confirm the attribute slugs under Products → Attributes. The URL uses the slug, not the label.
- The format is:
https://yoursite.com/product/product-name/?attribute_pa_attribute-slug=value-slug
For multiple attributes, you can combine them with an ampersand. You can read more about how variable products and attributes work here: https://woocommerce.com/document/variable-product/
If the variation link does not auto select on your site, it is often due to theme or JavaScript conflicts. In that case, please let us know and share your System Status Report via https://pastebin.com so we can take a closer look. Looking forward to your update.
I do not use product attributes, only has been applied to a few products…
I only set variations inside products in woo commerce.
I know that what I want to achieve can be done as a customer sent back the below link:
I cannot replicate this at my end, maybe it can be done at browser level somehow??
Thanks for the additional clarification and for sharing the example link, I can see exactly what you are trying to achieve here. Being able to send a customer a direct link that preselects a variation and shows the correct price is definitely a smart workflow.
I checked your product page at https://giantofficefurniture.com.au/product/uniflip/ and I noticed that when selecting variations, the URL does not change in the browser. That is unusual, as WooCommerce normally appends the attribute query parameters once a full variation is selected.
A few key questions to help narrow this down:
- Did this previously work on your site and then stop after a recent WooCommerce, theme, or plugin update?
- Were these variations created using the default WooCommerce variation system under the Variations tab, or are they being handled via a custom field or a variation plugin?
Even if you are not using global attributes, WooCommerce still generates URLs using the product level variation attributes, like: ?attribute_assembled=Fully+Assembled?attribute_size=2+Drawer
So the behavior should still work as long as they are true WooCommerce variations.
At this stage, I recommend running a quick theme test. Please temporarily switch to a default theme such as Storefront and test selecting variations again. If the URL starts updating correctly, that would confirm this is theme or JavaScript related.
You can read more about Storefront here: https://ww.wp.xz.cn/themes/storefront/ and here for how to test for conflict: https://woocommerce.com/document/how-to-test-for-conflicts/
I have tested with storefront theme installed, and URL’s do not update when different product variations are selected… ???
Thank you for the update and for taking the time to test this with the Storefront theme. I appreciate you checking that, as it helps narrow down where the issue may be coming from.
Alongside the theme test, could you also confirm if you performed a full plugin conflict test? This involves temporarily deactivating all plugins except WooCommerce, then testing the product page again to see if selecting variations updates the URL in the browser.
If the URL starts updating with only WooCommerce active, it would indicate that another plugin is interfering with the variation script. You can then reactivate the plugins one by one until the conflicting one is identified.
You can follow the general conflict testing steps here: https://woocommerce.com/document/how-to-test-for-conflicts/
Please let us know how the test goes, and we will be happy to continue troubleshooting with you.
Disabled All plugins except for Woo Commerce, URL’s did not update when all product variation selections were made…
Hi there!
Sorry for the confusion earlier, and thank you for taking the time to test this by disabling all plugins.
By default, WooCommerce does not append variation attributes to the URL when selections are made on the product page. So the URL not updating after selecting product variations is expected behavior and indicates that WooCommerce is working as designed.
WooCommerce can read variation attributes from a URL if they are already present, but it does not automatically modify or update the product link when customers choose variations.
If you would like the URL to change dynamically based on the selected variation, this would require custom development or a third-party plugin, as this functionality is not included in WooCommerce core.
If you need more in-depth support or want to consider professional assistance for customization, I can recommend WooExperts and Codeable.io as options for getting professional help.
Alternatively, you can also ask your development questions in the WooCommerce Community Slack as custom code falls outside our usual scope of support.
It seems we haven’t heard back from you for a while, so I’ll go ahead and mark this thread as resolved. Feel free to reach out whenever you’re ready to continue.
If you have time, we’d be grateful for a review: https://ww.wp.xz.cn/support/plugin/woocommerce/reviews/
You must be logged in to reply to this topic.