Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3658092
Make Group unavailable when 1 product is out of stock
Open

Comments

  • Thomas started the conversation

    Dear, I have several groups on my website. When 1 of the products in the group is sold out, I would like to have the group unavailable for purchase. Now, people can still add the group to the cart, without the sold out product. This means that my customers still get a discount on the product that is available in the group.

    Can you please help me?

    Thomas

  •  1,226
    Dustin replied

    Hi Thomas,

    Please add the custom code below. (How to add custom code? ↗):

    add_filter( 'woocommerce_product_is_in_stock', function ( $in_stock, $product ) {
        if ( $product->is_type( 'woosg' ) && ( $items = $product->get_items() ) && ( count( $items ) > 0 ) ) {
            foreach ( $items as $item ) {
                if ( ( $item_product = wc_get_product( $item['id'] ) ) && ! $item_product->is_in_stock() ) {
                    return false;
                }
            }
        }
        return $in_stock;
    }, 99, 2 );

    Best regards,
    Dustin

  •  2
    Thomas replied

    Hi Dustin,

    this did work out great! Thank you. The ticket can be closed.

    Thomas