As you can tell from the title I try to "automatically pre select the first in stock value in WooCommerce variable product dropdown".
Currently, I'm using the code below to pre-select the first variant, but I need this code to select the first IN STOCK variant. Any advice?
function fun_select_default_option( $args ) {
// Check the count of available options in dropdown
if ( count($args['options']) > 0 ) {
$args['selected'] = $args['options'][0];
}
return $args;
}
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'fun_select_default_option', 10, 1 );