• How can we set a default variant (especially for products with only one) so that users can add a product to a cart without having to choose? When there is only one color or size it doesn’t make sense to make the user choose those options. I expect shops will lose sales because users don’t realize they need to choose a variant and will get frustrated and leave.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author andrewmrobbins

    (@andrewmrobbins)

    @secretagency

    Hey there, try adding this PHP snippet to your WordPress theme:

    
    add_filter('shopwp_products_default_payload_settings', function($settings) {
    
        $settings['select_first_variant'] = true;
        return $settings;
    
    });
    

    Let me know if this doesn’t help!

    Thread Starter Secret Agency

    (@secretagency)

    Wow thanks Andrew for the quick reply and code! Unfortunately, that actually did kind of the opposite of what I am looking for. That selected a default variant when there was more than one – say Small out of Small, Medium and Large. I am looking for a way to select the only possible variant when thee is only one to choose from. So for example, say I have a hat that only comes in one size – “one size fits all” and one color – black. I want the user to be able to just hit add to cart and have it select the size and color automatically since those variants each only have one choice. Sorry if this was not clear. And thanks again for the prompt reply. 5 stars!

    Thread Starter Secret Agency

    (@secretagency)

    Actually, it looks like it did work. It is just that the variants I have for one-size-fits-all say “undefined” for some reason. But it is choosing that correctly.

    I wonder if there is a way to have it only choose a default when there is only one choice though? Because it is choosing a default when there are multiple variants, which is not ideal since someone could add a medium when they want a small, for example.

    In any case, thanks again- this is a great start.

    Thread Starter Secret Agency

    (@secretagency)

    I see. That is the expected behavior of the filter.

    `select_first_variant?

    Allows for selecting the first product variant on page load. This will only work with products that have one “option” to choose from. For example, it will work with a product that provides a color option, but not with products that provide color and size.

    Possible values
    true
    false Default`

    OK so, feature request! I’ll write it as a user story.

    “Select_Only_Single_Variants”

    As a shop owner, I would like customers to be able to quickly add products to their carts with only a single click when those products have variants with only one choice. For example, if I sell a hat that only comes in one color and one size, then clicking “add to cart” should add it to the cart immediately. However, if I sell a t-shirt in multiple sizes, the user should still have to choose a size to prevent them from anciently choosing the wrong size.

    Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to automatically choose default or single variant?’ is closed to new replies.