• I would like the option to remove the entire variable drop down menu(s) whenever there is only 1 option for every variation. The pseudo code:
    if( all variation options only have 1 value ) { remove all variation menu dropdowns }
    I found something but it also removed the add to cart button and quantity, and it did so indiscriminately:

    function removing_variable_add_to_cart_template(){
        global $product;
    
        // Only for variable products
        if( $product->is_type( 'variable' ) ){
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        }
    }

    I’ve shown a pic here.
    Here’s the page I took the screenshot on, a page where the code would be necessary.

    Now, you may be thinking, but what is the point? If there is only 1 variation, why not just make it a simple product? I can explain in a reply if asked, as it’s pretty much useless information. In short, variable products have functionality that I need.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Tomi

    (@tomitech)

    I found in another thread:
    Hannah S. said that “WooCommerce product variations don’t know how to handle conditional logic.”

    …but how can this be if the file that deals with this is written in PHP?
    single-product/add-to-cart/variable.php

    Is PHP not a conditional language?

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @tomitech!

    What was meant there is that by default, WooCommerce variation type products don’t have conditional logic (baked in), but it can, like everything else, with some code be extended. Or by using another plugin like https://woocommerce.com/products/gravity-forms-add-ons/

    If you prefer the code way, then maybe this could be a good starting point:

    https://stackoverflow.com/questions/52564972/hide-variable-product-dropdown-that-has-a-unique-variation-selected-by-default-i/52565307#52565307

    Cheers!

    Thread Starter Tomi

    (@tomitech)

    Yes, that is exactly what I have been looking for, THANK YOU SO MUCH! So far it seems as if all I had to do was remove ” && sizeof($default_attributes) == 1″ so that it just looks at the variations. At the moment it seems to work, but I have a feeling it’s flawed, because when I echo, it only refers to the first attribute:

    	echo reset($variation['attributes']);
    	echo nl2br ("\n");
    	echo reset($default_attributes);
    	echo nl2br ("\n");

    returns

    china
    china

    even though this product has 2 attributes (1 variation though, since both attributes have only 1 value). But I don’t think it matters cuz there’s only 1 variation, so I’m not sure if there’s even a point in that if statement:

    if( reset($variation['attributes']) == reset($default_attributes) ) :

    Anyway, I think it should work fine as I don’t see any reason for any further logic after it’s been determined there is only 1 variation. This was a great learning experience. I got to make my own little modification, even if its super tiny. Thanks again!

    I’m still willing to look into this further though, because of some of the unknowns I mentioned.

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove entire variable dropdown menu altogether’ is closed to new replies.