Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @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

    (@ershadzolfi)

    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.
    • This reply was modified 5 years, 10 months ago by ershadzolfi.
    • This reply was modified 5 years, 10 months ago by ershadzolfi.
    Thread Starter ershadzolfi

    (@ershadzolfi)

    Hi @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, customizations are outside the scope of the support we can offer, but we have a customizations page with resources for contacting a developer for help. You can also ask about this on the WooCommerce Slack Community or WooCommerce FB group which are great places for customization questions like this.

    I will also leave this thread open in case any others have suggestions.

    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.