inovve

Auto select first available options from a variation on WooCommerce variable products

Jun 17th, 2021
794
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter('woocommerce_dropdown_variation_attribute_options_args','fun_select_default_option',10,1);
  2. function fun_select_default_option( $args)
  3. {
  4.  
  5.     if(count($args['options']) > 0) //Check the count of available options in dropdown
  6.         $args['selected'] = $args['options'][0];
  7.     return $args;
  8. }
RAW Paste Data