Thanks, Juan; your links inspired me to implement my solution. I like to share it here. Maybe somebody needs it as well.
add_action('woocommerce_dropdown_variation_attribute_options_args', auto_select_color',10,1);
function auto_select_color($args)
{
if ($favorateColor === "blue")
{
if( 'pa_color' == $args['attribute'])
{
$args['selected'] = $args['options'][1];
// Blue color index is 1;
}
return $args;
}
else if ($favorateColor === "red") {
if( 'pa_location' == $args['attribute'] )
{
$args['selected'] = $args['options'][0];
// Red color index is 0;
}
return $args;
}
}
-
This reply was modified 4 years, 6 months ago by hossham2020.
Hey @alexmigf, I appreciate it if you can help me with this issue!