简体   繁体   English

如果变体是我们的库存,如何在下拉列表中的产品变体旁边添加售罄文本?

[英]How to add sold out text next to product variant in drop down if variant is our of stock?

In my woocommerce variants products, I have managed to disable the variant option in the drop down if the variants has all its products out of stick.在我的 woocommerce 变体产品中,如果变体的所有产品都不可用,我已经设法禁用下拉列表中的变体选项。 What I want to do though is also add a 'Sold Out' text next to the disabled variant value in the drop down menu.不过,我想做的是在下拉菜单中的禁用变体值旁边添加一个“已售罄”文本。

How can this be done:如何才能做到这一点:

/**
 * Disable out of stock variations
 * https://github.com/woocommerce/woocommerce/blob/826af31e1e3b6e8e5fc3c1004cc517c5c5ec25b1/includes/class-wc-product-variation.php
 * @return Boolean
 */

function wcbv_variation_is_active( $active, $variation ) {
 if( ! $variation->is_in_stock() ) {
 return false;
 }
 return $active;
}
add_filter( 'woocommerce_variation_is_active', 'wcbv_variation_is_active', 10, 2 );

You can try the instructions here and modify the sold out text to be what you would like: https://www.skyverge.com/blog/add-sold-out-to-woocommerce-variable-product-dropdown/您可以尝试此处的说明并将已售罄的文本修改为您想要的: https://www.skyverge.com/blog/add-sold-out-to-woocommerce-variable-product-dropdown/

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

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