WooCommerce: показать или скрыть кнопку «Нет на складе» в зависимости от состояния запасов. ⇐ Jquery
-
Anonymous
WooCommerce: показать или скрыть кнопку «Нет на складе» в зависимости от состояния запасов.
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
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
Мобильная версия