Woocommerce Product Add-ons - Auto-select first option - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: Woocommerce Product Add-ons - Auto-select first option (/showthread.php?tid=29737) |
Woocommerce Product Add-ons - Auto-select first option - EFitzpatr7 - 04-21-2016 The agency I work for are trying to get a client's website to auto-select the first option on the maintenance packages for their products. Currently, we are using an if statement within a foreach. The code below is the script we are currently using: PHP Code: <?php foreach ( $addon['options'] as $i => $option ) : The code above currently doesn't select any of the radio buttons, but if we change PHP Code: <?php echo sanitize_title( $option['label'] ); ?>" <?php checked( $current_value, 1 ); ?> to PHP Code: <?php echo sanitize_title( $option['label'] ); ?>" <?php checked( $current_value, 0 ); ?> the final radio point is selected. The only issue we have then got is the fact that we will then have to manually go and change every single product, and move the option "None" to the end of the list, as it is currently the first option on all of the products. Is there a way with the code above to be able to auto-select the first option rather than the last? The name for the first option is: addon-2491-maintenance-packages-0. Any help is much appreciated. |