I have some products with a Size attribute and 3 Variations (small, medium, large). I also have 3 shipping classes, one for each Size.
Any product's Small variation will use the Small Product Shipping Class, and the same goes for Medium and Large.
I can assign each shipping class to each variation manually but it's time-consuming, prone to errors, and redundant in this case (create a Large variation, then assign a Large shipping class)
Is there any way to connect a shipping class to a specific variation, so when I create the variation it comes with the corresponding shipping class already assigned?
The following code should do the trick, auto adding To Product variations, the shipping class ID based on product attribute "Size" term value assigned to the variation.
It requires to have the same terms for Size product attribute and for shipping classes terms too ("Small", "Medium" and "Large" in your case)
The code:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.