ResolvedOut of stock on variations

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28286
    escozul
    Participant

    Hello,

    On our eshop, products that are out of stock are getting disabled and should not be available for viewing or ordering anymore.

    So we have the woocommerce option “Hide Out of Stock Products” enabled. That works for searches and all. But when you are in a product the variations that are out of stock are still showing. When a customer tries to select one they get a message that the product is not available.

    For example check this product: https://www.paramythi.com.gr/product/203800-σετ-φόρμας/ (Don’t mind the greek)

    Only size 1 is available. The others are out of stock. So if a user gets into that product he might think that it’s available in all sizes! How do I make it hide the variations options for out of stock variations?

    #28309
    Althemist
    Keymaster

    Hello escozul,

    I am afraid there is no way to avoid this and it’s not theme related. Unfortunately, this is how WooCommerce work. If a variation exists it will be shown regardless of it’s stock status. It’d be the same with any WooCommerce theme.

    #28317
    escozul
    Participant

    Hello,

    Please allow me to disagree.
    Indeed Woocommerce does not support that functionality “out of the box” but… you can add that snippet in the functions.php:

    /**
     
     * @snippet       Disable out of stock variations @ WooCommerce Single
     
    */
     
    add_filter( 'woocommerce_variation_is_active', 'cs_grey_out_variations_out_of_stock', 10, 2 );
     
    function cs_grey_out_variations_out_of_stock( $is_active, $variation ) {
     
        if ( ! $variation->is_in_stock() ) return false;
     
        return $is_active;
     
    }

    and that could do the trick. The issue it though that it is not working currently on the theme. It’s possible that you are not using the woocommerce_variation_is_active in your theme?

    Just speculation there. Maybe you use that filter for other purposes and negate the effect from the functions.php file. Anyway, since it is doable by using functions.php it is theme related 😉

    #28333
    Althemist
    Keymaster

    That could do the trick for simple variations and ONLY if you have up to 5-6 variations. It was tested numerous and times and it doesn’t work correctly with larger number of variations or if you use complex variations consisting of more than one attribute (e.g. color AND size).

    It’s discussed numerous times by Rodolfo Melogli (the author of the snippet above). Check the comments bellow: 😉 :

    WooCommerce: Disable Out of Stock Variations @ Variable Product Dropdown

    We do not modify the default WooCommerce behavior and filters (it’s not allowed on ThemeForest)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in and have valid license to reply to this topic.

License required for any item belonging to this account
AlThemist

AlThemist

sales 18045, followers 753
Login and Registration Log in · Register