在目录视图中显示“缺货”Woocommerce
问题描述:
经过数小时和数小时的研究,我无法获得此功能。我希望有一个人可以帮助我。在目录视图中显示“缺货”Woocommerce
在woocommerce中,缺货消息仅显示在单个产品页面上,而不显示在目录页面上。这意味着有人首先必须点击产品才能发现它已售罄。游民。由于我们销售的是独特的产品,因此我们必须展示缺货产品。 “缺货”通知必须直接在产品图像下可见。
W're垂死的解决方案:)
亲切的问候,
鲁斯
答
发现这个片段here。在我的网站上完美工作。
//add action give it the name of our function to run
add_action('woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25);
//create our function
function wcs_stock_text_shop_page() {
//returns an array with 2 items availability and class for CSS
global $product;
$availability = $product->get_availability();
//check if availability in the array = string 'Out of Stock'
//if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
if ($availability['availability'] == 'Out of stock') {
echo apply_filters('woocommerce_stock_html', '<p class="stock ' . esc_attr($availability['class']) . '">' . esc_html($availability['availability']) . '</p>', $availability['availability']);
}
}
+0
这也适用于我。 – furtive 2015-08-25 22:16:52
答
我知道它已经相当一段时间,但我只想做同样的,发现有两班,在循环中锂元素。
VS
<li class="first ... instock">
如果只是要更改的标记,也许只是做了CSS,不挂接到woocommerce只是消息。
答
在2017年,这个片段将工作:
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_stock', 10);
function woocommerce_template_loop_stock() {
global $product;
if (! $product->managing_stock() && ! $product->is_in_stock())
echo '<p class="stock out-of-stock">Out of Stock</p>';
}
答
最简单的方法将是使用CSS:
在目录中的每个产品都会有一个< li>标签。如果产品有库存就会有这个类“使用inStock”如果没有股吧它将有这个类“outofstock”
所以,你可以创建这个CSS:
.outofstock:before{
content: url(http://image.png);
position: absolute !important;
top: 9px;
left: 7px !important;
text-align: center;
z-index: 9999999;
}
请记得用您的image.png网址替换。
请检查: - http://kb.oboxthemes.com/articles/out-of-stock-products-visible-on-shop/ – Khushboo 2014-09-27 09:33:08