Woocommerce Product Add-ons – Auto-select first option

Is this form only filled out once? Or can users be sent back to it, needing it to know what they have already selected?

If the former, it’s not too difficult to select the option you want.

You just need to replace this:

<?php checked( $current_value, 1 ); ?>

with this:

<?php checked( '2491-maintenance-packages-0', sanitize_title( $option['label'] ) ); ?>

The checked() function simply returns the HTML checked='checked' when the two values sent to it are a match, thereby instructing the browser to render that option pre-checked. It is most often used not to pre-check a default option, but rather to ensure that when a user visits an options page, whatever the option is currently set to in the database is rendered checked. WordPress’ checked() function is therefore simply syntactic sugar to save you having to fill your code with if statements.

The reason you only had the last option selected when you used $current_value, 0 was likely because every single option came to the form unselected, therefore $current_value was always equal to 0, therefore every option became selected… and because only one radio option can be selected at a time, the last one ends up overriding all the rest.

Now, it’s important to note that your flow here is not necessarily intuitive. I’m not sure how the rest of your site works, but as I hinted at the top of this answer, if a user needs to come to this page with whatever they have selected being already pre-checked, you’re going to need to modify your flow. Otherwise their own settings will be overridden by your ‘default option’ once this form is saved.