2
votes

I am currently working on a WordPress eCommerce website, where the chosen shopping platform is WooCommerce.

I would like the ability to hide 'Out of Stock' product variations but cannot seem to find a solution, anywhere on the Internet.

For example, say I have a Shoe Shop whereby the website sells Shoes. Product Drop Down Menu is as follows:

  • Shoe Size
    • 9
    • 10
    • 11
  • Shoe Colour
    • Red
    • Blue
    • Yellow
  • Shoe Style
    • Trainers
    • Casual
    • Velcro

Say the website does not have Blue Size 9 Trainers. If a shopper selects any 1 of those options from the drop down menu, the other options will be removed/greyed out.

I understand that there is a 'Hide Out of Stock' option, within the WooCommerce Settings but this only affects the Main Product rather than the Product Variations.

I have tried manually deleting the Product Variation, within the Product Page's backend but the variation still exists; a message simply appears saying 'This product is unavailable. Please select another combination.'

Any guidance on this matter, would be greatly appreciated.

3

3 Answers

1
votes
function custom_wc_ajax_variation_threshold( $qty, $product ) {
    return 10;
}

add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );

paste this code into your functions.php file

0
votes

Simply paste the following into functions.php

function custom_wc_ajax_variation_threshold( $qty, $product ) {
    return 10;
}

add_filter( 'woocommerce_ajax_variation_threshold','custom_wc_ajax_variation_threshold', 10, 2 );

Then change the 'return 10;' to however many variations you have.

Please note this may slow down page loading time depending on your hosting

0
votes

First, leave the box to ‘Hide out of stock items from the catalog’ unchecked. Then paste this into the appropriate plugin or theme file:

function hide_out_of_products( $is_visible, $id ) {
$product = new wC_Product( $id );

    if ( ! $product->is_in_stock()) {
        $is_visible = false;
    }

    return $is_visible;
}
add_filter( 'woocommerce_product_is_visible', 'hide_out_of_products', 10, 2 );