Thursday 18 March 2021

Woocommerce 2 Variable Product Dropdown List, force first one to always show all options

I have 2 drop down select fields in my variable WooCommerce product.

1st one is Type of Product (in my case framed or unframed artwork) 2nd one is Size of Artwork.

Thanks to this code:

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'dropdown_variation_attribute_options', 10, 1 );
function dropdown_variation_attribute_options( $args ){

    // For attribute "Type"
    if( 'Type' == $args['attribute'] )
        $args['show_option_none'] = __( 'Select Framed or Unframed Artwork', 'woocommerce' );

    // For attribute "Sizes"
    if( 'Size' == $args['attribute'] )
        $args['show_option_none'] = __( 'Select Size of Artwork', 'woocommerce' );

    return $args;
}

I can display the default text when nothing has been selected for each drop down select field individually.

The problem I have now is that I need to force the 1st drop down list to always show all options and when a selection is made, to reset the 2nd one.

Example:

I offer Variation A,B,C,D in the first drop down list. The 2nd Drop down list would have variations 1,2,3,4.

Lets say i choose A, the second drop down select field will now limit the options to 1 and 3 as A is not available with 2 and 4.

Lets say i choose 3 now in the 2nd drop down select field, which will limit the first drop down select field's choices to A and B as C and D are not available in 3.

But i need to see C and D as well in the first one so people can always start from the beginning when they choose a product.

Any help will be appreciated.



from Woocommerce 2 Variable Product Dropdown List, force first one to always show all options

No comments:

Post a Comment