简体   繁体   中英

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. 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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