Title: Stock availability for each variation
Last modified: January 18, 2017

---

# Stock availability for each variation

 *  [newshop](https://wordpress.org/support/users/newshop/)
 * (@newshop)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/)
 * Hello,
    I noticed that the availability info (in stock/not in stock) in wishlist-
   view table only works well for single product. If there is a variable product
   with some variations in stock and others out of stock, the table still says “
   in stock”. Is it possible to edit the code in order to list all possible variations
   with their specific stock lever, for example:
 * Red T-Shirt
    Size S: in stock Size M: in stock Size L: not in stock
 * That would be sooo great 🙂
    Any help would be really appreciated!
    -  This topic was modified 9 years, 4 months ago by [newshop](https://wordpress.org/support/users/newshop/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [newshop](https://wordpress.org/support/users/newshop/)
 * (@newshop)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8668419)
 * There is this plugin WooCommerce Availability Chart that shows the available 
   stock amount. Maybe this could help to create a code..
 *  Plugin Author [YITHEMES](https://wordpress.org/support/users/yithemes/)
 * (@yithemes)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8669429)
 * Hi newshop!
 * You’re right!
    Please, try to follow the following steps to customize plugin
 * 1. Overwrite default wishlist-view.php template, copying it from wp-content/plugins/
   yith-woocommerce-wishlist/includes and pasting it under wp-content/themes/<your
   theme or child folder>/woocommerce/
 * 2. In your brand new template, replace the following code
 *     ```
       <?php
         if( $stock_status == 'out-of-stock' ) {
           $stock_status = "Out";
           echo '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>';
         } else {
           $stock_status = "In";
           echo '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>';
         }
       ?>
       ```
   
 * (lines 189-197) with this code
 *     ```
       <?php
         if( $product->is_type( 'variable' ) ){
           $variations = $product->get_available_variations();
           if( ! empty( $variations ) ){
             foreach ( $variations as $variation ){
               $variation = $product->get_child( $variation['variation_id'] );
               echo $variation->get_formatted_variation_attributes();
               echo $variation->is_in_stock() ? '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>' : '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>';
             }
           }
         }
         elseif( $stock_status == 'out-of-stock' ) {
           $stock_status = "Out";
           echo '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>';
         } else {
           $stock_status = "In";
           echo '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>';
         }
       ?>
       ```
   
 * Hope this helps
    Have a nice day
 *  Thread Starter [newshop](https://wordpress.org/support/users/newshop/)
 * (@newshop)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8669561)
 * Thank you very much! First I thought everything works like a charm but then I
   noticed that the products in stock are marked as “not in stock” and vice versa.
   I think I have to switch a part of the code but I dont know how. Could you please
   help me with that?
 *  Thread Starter [newshop](https://wordpress.org/support/users/newshop/)
 * (@newshop)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8669580)
 * Ok, I just switched the two spans and now its correct. Do you agree with my changes?
 *  Plugin Author [YITHEMES](https://wordpress.org/support/users/yithemes/)
 * (@yithemes)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8669650)
 * Yes, of course 🙂
    Sorry for the issue 😀
 * I’m marking this topic as solved
 * If you enjoy our plugin and our support, please, don’t forget to leave us a 5
   star rating, and to consider buying our premium version of wishlist plugin 🙂
 * Have a nice day
 *  Thread Starter [newshop](https://wordpress.org/support/users/newshop/)
 * (@newshop)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8669662)
 * Awesome, thank you so much for the great support, 5star rating will follow!
 *  Thread Starter [newshop](https://wordpress.org/support/users/newshop/)
 * (@newshop)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8720748)
 * Hello, I wanted to include the code you gave me in a shortcode and then I wanted
   to include that shortcode in a form that I created with contact form 7 and contact
   form 7 dynamic text extension. But it didnt work. The author of contact form 
   7 dynamic text extension gave me the following advice, but I dont know how to
   edit the code correctly. Could you please help me with that? Many thanks in advance!
 * > Your shortcode is not coded correctly and you need to fix it. You are echoing
   > your output, not returning it.
   > All shortcodes must return, not echo.
   > Your $output variable that you are returning isn’t even defined, so you’re 
   > returning null. You need to define it at the beginning of your function, append
   > your strings to that variable, and then return it. Don’t echo anything.
 * Here is the code I used:
 *     ```
       function availability_info() {
       global $product;
       if( $product->is_type( 'variable' ) ){
       	$variations = $product->get_available_variations();
       	if( ! empty( $variations ) ){
       		foreach ( $variations as $variation ){
       			$variation = $product->get_child( $variation['variation_id'] );
       			echo $variation->get_formatted_variation_attributes() . (":") .(" "); echo $variation->is_in_stock() ? ("<span style=color:#00b805;>") . __( 'In Stock', 'yith-woocommerce-wishlist' ). ("</span>") . ("<br />") : ("<span style=color:#cb0000;>") . __( 'Out of Stock', 'yith-woocommerce-wishlist' ). ("</span>") . ("<br />");
       		}
       	}
       }
       elseif( $stock_status == 'out-of-stock' ) {
       	$stock_status = "Out";
       	echo __( 'Out of Stock', 'yith-woocommerce-wishlist' );
       } 
       else {
       	$stock_status = "In";
       	echo __( 'In Stock', 'yith-woocommerce-wishlist' );
       }							
       return $output;
       }
       add_shortcode( 'instock', 'availability_info' );
       ```
   
    -  This reply was modified 9 years, 4 months ago by [newshop](https://wordpress.org/support/users/newshop/).

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Stock availability for each variation’ is closed to new replies.

 * ![](https://ps.w.org/yith-woocommerce-wishlist/assets/icon-128x128.gif?rev=3129302)
 * [YITH WooCommerce Wishlist](https://wordpress.org/plugins/yith-woocommerce-wishlist/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yith-woocommerce-wishlist/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yith-woocommerce-wishlist/)
 * [Active Topics](https://wordpress.org/support/plugin/yith-woocommerce-wishlist/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yith-woocommerce-wishlist/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yith-woocommerce-wishlist/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [newshop](https://wordpress.org/support/users/newshop/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/stock-availability-per-variation/#post-8720748)
 * Status: not resolved