Woocommerce: Changing the variations select default value?

At my site i want to change the default value of the selecter that appears, when different variations exists. If anyone can give me a clue of how and where this is done, it would be highly appreciated!

Related posts

3 comments

  1. On the Product Edit page for the variable product, click on the “Variations” tab.
    Once you setup variations for the Colour you can set a “Default selection” at the bottom: http://cld.wthms.co/7LIv

    This will be the default option selected when a customer visits the page (if it is in stock).
    Example: http://cld.wthms.co/YQFO

  2. If like me you’d like to have a default variation option selected without having to go through every Product and select a default via the admin then you need to alter the variable.php file which is located at woocommerce/templates/single-product/add-to-cart/variable.php (please do not alter the WooCommerce Plugin file – rather copy it to your Themes directory as per best practice).

    The key here is the final else condition on line 35. This which determines what the default variation value will be. Simply alter:

    $selected_value = '';

    …to…

    $selected_value = $options[0];

    This will set the default value to be the first item in the array of product variations defined in the backend. That way your Add to Cart button is always shown by default and the user still has the ability to select another variation if they wish.

    Why this isn’t in WooCommerce core I don’t know.

    (Note this method still allows the admin to set a specific default variation value from the WPAdmin which will overide the default which gets set using my code above)

  3. I know it’s a little late at this point but just in case anyone else runs into this problem. This should allow you to change the default value text.

    Copy and paste this into your themes functions.php file. It may not be the best way to do it but it worked great for me.

    /* Change Woocommerce Default Value Text */
    add_filter('gettext',  'choose_option');
    add_filter('ngettext',  'choose_option');
    
    function choose_option($translated) {
         $translated = str_ireplace('Choose an option',  'Select Size',  $translated);
         return $translated;
    }
    

    NOTE: This will change the default value text throughout the entire site. Just a heads up!

Comments are closed.