Leave a Reply

Your email address will not be published. Required fields are marked *

2 Comments

  • Hello,

    Thank you for your tutorial !

    It works perfectly when there’s only one variation. But when I have several attributes with several variations, the attributes that follow take into consideration only one variation of the parent attribute.

    Example :
    I have several attributes with several variations:

    1st attribute: 500g, 900g, 2.27kg
    2nd attribute: Banana, chocolate, cookie

    Issue :
    By selecting: 2.27kg / chocolate -> variation displayed “out of stock”, while it is available in stock, because it takes into consideration the out of stock for the item available in 500g or 900g .

    opposite problem: -> 2.27kg / strawberry -> variation displayed “in stock”, when it is not in stock

    Would you please tell me how to solve this issue please ?

    Thank you

    • Hi Anthony,

      Thanks for reading and leaving a comment. You’re right that this code is only working with one variation. If you have multiple variations to check, you’ll need to add additional code to this section to make sure you’re checking for the variation that has been selected:

      if ( $variation_id ) {
      $variation = wc_get_product( $variation_id );
      $stock_status = $variation->get_stock_status();

      You have to make sure you’re checking the stock status for the correct $variation_id.