'Set Default value for WooCommerce Product Add-Ons in a Composite Product

I want to set a default value of a Product Add-On field inside of a Composite Product. I am able to set the default value of a Product Add-Ons field with JavaScript.

$('#addon-6640-additional-items-0').val('10');

But, if I use this product inside of a Composite Product the default value is not working. I did notice the the ID of the input field changes once it is included in a Composite Product. But, neither the updated ID nor the original ID work with the product in the Composite Product.

$('#addon-1643457870-additional-items-0').val('10');

In addition, I have tried to set the default value using query parameters. But this too has failed. This means that when a Composite Product that has Product Add-Ons are added to the cart, but then edited "Edit Cart" the Product Add-Ons values are not persistent and must be entered again.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source