0

I'm trying to hide the variation description on product pages if the variation's stock is >=1. Following this I have made this code which is not working:

add_action ('woocommerce_after_single_variation', 'hide_descriptions', 10);

function hide_descriptions() {

    $stock_qty = $product->get_stock_quantity();
   
    if ($stock_qty>=1)
     ?>
    <div class="woocommerce-variation-description" style="display: none!important;"></div>
    <?php
    
}

I've also tried with the action hook 'woocommerce_single_variation' since the class="woocommerce-variation-description" is located inside the class="woocommerce-variation single_variation" - and the latter class is called by the function woocommerce_single_variation().

But how do you access a nested class with a hook that targets its parent?

LouMJ
  • 13
  • 3

1 Answers1

0

first of all, I see you didnt have opening and closing if brackets. And u wrote greater, not lower than 1, and try to use same priority as mentioned in the answer you looked up - 50.

 add_action ('woocommerce_after_single_variation', 'hide_descriptions', 50);

function hide_descriptions() {

    $stock_qty = $product->get_stock_quantity();
   
    if ($stock_qty < 2) { ?>

       <div class="woocommerce-variation-description" style="display:none"></div>
 
<?php }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Mantc
  • 131
  • 7
  • Thank you for your input. Unfortunately, I still get the "there's a critical error" message. I think it might be because my site is using Ajax – LouMJ Jun 05 '21 at 10:46