Advertisement
Guest User

Out of Stock Variation

a guest
Oct 10th, 2019
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. //Filter attributes and variations that are in stock
  2.  
  3. add_action( 'woocommerce_before_shop_loop_item_title', 'wk_out_of_stock_variations_loop' );
  4. function wk_out_of_stock_variations_loop(){
  5.     global $product;
  6.     if ( $product->product_type == 'variable' ) { // if variation product is out of stock
  7.         $available = $product->get_available_variations();
  8.         if ( $available )foreach ( $available as $instockvar ) {
  9.             if ( isset($instockvar['attributes']['attribute_pa_megethos'] ) ) {
  10.              
  11.              
  12.         if(isset($_GET['filter_megethos'])){
  13.            
  14.            $destostock = $_GET['filter_megethos'];
  15.              
  16.          
  17.           $array = explode(',', $destostock);
  18.          
  19.  
  20.  
  21.     if (in_array($instockvar['attributes']['attribute_pa_megethos'], $array )&& (!$instockvar['max_qty']>0)){
  22.            global $product;
  23.            $id = $product->get_id();
  24.      
  25.             echo "<style>.post-$id{display: none}</style>";
  26.  
  27.     }
  28.           else{
  29.            
  30.           if (in_array($instockvar['attributes']['attribute_pa_megethos'], $array )&& ($instockvar['max_qty']>0)){
  31.            global $product;
  32.            $id = $product->get_id();
  33.      
  34.             echo "<style>.post-$id{display: block !important}</style>";
  35.          
  36.           }
  37.           }
  38.            
  39.         }
  40.     }  
  41.  
  42. }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement