Title: randomize default variable
Last modified: July 30, 2020

---

# randomize default variable

 *  Resolved [ershadzolfi](https://wordpress.org/support/users/ershadzolfi/)
 * (@ershadzolfi)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/)
 * Hi
    In variable products how can i randomize the default value? (default value
   change each time)
 * Tnx.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Austin M – a11n](https://wordpress.org/support/users/apmwebdev/)
 * (@apmwebdev)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/#post-13191582)
 * Hi [@ershadzolfi](https://wordpress.org/support/users/ershadzolfi/). I don’t 
   think there’s a way to accomplish this out of the box, but we might be able to
   suggest something if we had a better idea of what you were trying to accomplish
   from a big-picture perspective. Can you give us some more context about this 
   question?
 *  Thread Starter [ershadzolfi](https://wordpress.org/support/users/ershadzolfi/)
 * (@ershadzolfi)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/#post-13192002)
 * Look,
    product “bag” has three options:
 * -please choose an option
    -option A -option B -option C
 * i want to hide the choose and option and choose one of these options as default(
   available in stock)
 * **there is code but it has problem(problem is that the array contains the out
   of stock options too):**
 *     ```
       add_filter('woocommerce_dropdown_variation_attribute_options_args','fun_select_default_option',10,1);
       function fun_select_default_option( $args)
       {
           if(count($args['options']) > 0)
               $args['selected'] = $args['options'][0];
       }
       ```
   
 * **if the option A be out of stock , this array doesnt work because option A is
   the first value of array($args[‘options’][0]).**
    ** if you can somehow add filter
   that array has the in stock options.
 * thank you
    -  This reply was modified 5 years, 10 months ago by [ershadzolfi](https://wordpress.org/support/users/ershadzolfi/).
    -  This reply was modified 5 years, 10 months ago by [ershadzolfi](https://wordpress.org/support/users/ershadzolfi/).
    -  This reply was modified 5 years, 10 months ago by [ershadzolfi](https://wordpress.org/support/users/ershadzolfi/).
 *  Thread Starter [ershadzolfi](https://wordpress.org/support/users/ershadzolfi/)
 * (@ershadzolfi)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/#post-13193971)
 * [@apmwebdev](https://wordpress.org/support/users/apmwebdev/)
 *  [Austin M – a11n](https://wordpress.org/support/users/apmwebdev/)
 * (@apmwebdev)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/#post-13195970)
 * Hi [@ershadzolfi](https://wordpress.org/support/users/ershadzolfi/), thanks for
   the clarification. I don’t know of a way to accomplish this with a plugin, so
   your customization is probably the right direction to go here. Per our [support policy](https://woocommerce.com/support-policy/#customisation),
   customizations are outside the scope of the support we can offer, but we have
   a [customizations page](https://woocommerce.com/customizations/) with resources
   for contacting a developer for help. You can also ask about this on the [WooCommerce Slack Community](https://woocommerce.com/community-slack/)
   or [WooCommerce FB group](https://www.facebook.com/groups/advanced.woocommerce/)
   which are great places for customization questions like this.
 * I will also leave this thread open in case any others have suggestions.
 *  [Austin M – a11n](https://wordpress.org/support/users/apmwebdev/)
 * (@apmwebdev)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/#post-13222986)
 * We haven’t heard back from you in a while, so I’m going to mark this as resolved.
   Feel free to start a new thread if you have any further questions!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘randomize default variable’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Austin M – a11n](https://wordpress.org/support/users/apmwebdev/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/randomize-default-variable/#post-13222986)
 * Status: resolved