I was looking to do the same thing, so i thought I share what worked for me. Place in footer:
<?php //You only need this if you want this to run on a specific page. If you want it on every page, then remove the if statement if (is_page('my-page-slug')){ ?> <script> jQuery('.my-class select option') .each(function() { var optionText = jQuery(this).html(); //if there are 2 spaces ( ), then it is our option. change the variable depending on your needs. //otherwise replace option tag with optgroup var m = optionText.match(/( ){2}(.*)/g); if (!m) jQuery(this).replaceWith('<optgroup label="'+optionText+'"></optgroup>'); }); </script> <?php } ?>