WooCommerce: показать или скрыть кнопку «Нет на складе» в зависимости от состояния запасов.Jquery

Программирование на jquery
Ответить
Anonymous
 WooCommerce: показать или скрыть кнопку «Нет на складе» в зависимости от состояния запасов.

Сообщение Anonymous »


I've got a button that should appear depending upon whether or not a product or one of its variations (if it's a variable product) is out of stock. If it's in stock, don't display it.

Been playing with lots of scripts but nothing seems to stick. Here's where I am currently at:

Example: https://bplsource.com/product/techniglo ... wder-free/

HTML:

\n\tOut of stock, Can be backordered PHP with JavaScript:

// Add Custom Content Before 'Add To Cart' Button On Product Page function my_content() { global $product; // Check if the product or any of its variations is out of stock $is_out_of_stock = false; if ($product->get_manage_stock() && $product->get_stock_quantity() is_type('variable') && !$is_out_of_stock) { foreach ($product->get_children() as $variation_id) { $variation = wc_get_product($variation_id); if ($variation && $variation->get_manage_stock() && $variation->get_stock_quantity() jQuery(function($) { var isOutOfStock = ; if (!isOutOfStock) { $('.stock.out-of-stock').hide(); } });

Источник: https://stackoverflow.com/questions/780 ... conditions
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»