简体   繁体   English

如何在WooCommerce中为CSS数量分配CSS类?

[英]How to assign a CSS class to the Stock Quantity in WooCommerce?

I'm trying to display Stock Quantity text in the following format. 我正在尝试以以下格式显示“库存数量”文本。

"How Many In Stock?" “有多少库存?” "20" “20”

You can check it live on the following link: 您可以通过以下链接实时查看它:

https://spendr.dk/shop/ https://spendr.dk/shop/

I'm using the following code. 我正在使用以下代码。

add_action('woocommerce_after_shop_loop_item','bbloomer_show_stock_shop', 10);

function bbloomer_show_stock_shop() {
global $product;
if ( $product->stock ) { // if manage stock is enabled 
if ( number_format( $product->stock,0,'','' ) < 3 ) { // if stock is low
echo '<div class="remaining">Only ' . number_format($product->stock,0,'','') . ' left in stock!</div>';
} 

else {
echo '<div class="remaining">' . 'How many in stock?</div>' . 
number_format($product->stock,0,'','');
}
}
}

Now I want to adjust the "Stock Quantity" (Example: 20). 现在,我要调整“库存数量”(例如:20)。 I'm trying to add a CSS Class to the stock quantity. 我正在尝试将CS​​S类添加到库存数量中。 I want to show it, right next to the "How Many In Stock?" 我想在“有多少库存?”旁边显示它。 text. 文本。

How can I add a CSS class to the Stock Quantity? 如何在库存数量中添加CSS类? in PHP. 在PHP中。

Thank You. 谢谢。

First, modify your style for remaining class 首先,修改剩余课程的样式

ie .remaining { display: inline-block; } .remaining { display: inline-block; } .remaining { display: inline-block; }

Second, replace div with span 第二,用span代替div

<div class="uniqstock"> 20</div> to <span class="uniqstock"> 20</span> <div class="uniqstock"> 20</div><span class="uniqstock"> 20</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM