All variant URLs are available to us and we can provide you with a list of ALL ?variant=xxxxxxxxx URLs of ALL product variants.
This also means we have all ?variant=xxxxxxxx exceptions
Just to confirm - you’d like each individual version of a product page that contains the variant ID to be a unique canonical URL?
It should be possible to use liquid to set up logic and conditions that when a page is a product page, that the canonical URL has the variant ID appended to it. You could also create a list of exception urls so that the default behaviour keeps for those variants that need the canconical URL without the variant. An example of what this could look like might be something like:
In this case when a variant’s URL is in the exception list array, it’s URL will appear as just the regular shop URL but if it’s not in the exception list it would be appended with the variant.url Liquid object. This code would be added where your themes canonical urls are being defined, likely in the theme.liquid file.
This is just a basic example of how this could be implemented, so you might need to adjust and test for your own purposes before deploying to any live themes - also it’s worth keeping Googles own duplicate content best practices.
We are well aware of duplicate content guidelines and all product variants have unique titles. Google is currently even ignoring some of the product page variant canonicals in favor of indexing these product variants (Canonicals are not directives for Google).