Delete stock status for a specific product label - Woocommerce

I try to hide the stock status on a single product page only when the product is marked as "preorder".

So far, I have added the code below to my functions.php file to change the text of the add to cart button for this particular tag. Any idea what code should / could have been added to achieve this?

//For single product page add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 + function woo_custom_cart_button_text() { global $product; if ( has_term( 'Preorder', 'product_tag', $product->ID ) ) : return __( 'Pre order Now !', 'woocommerce' ); else: return __( 'In Winkelmand', 'woocommerce' ); endif; } 
+5
source share
1 answer

For this purpose, you should try the woocommerce_stock_html filter:

 add_filter( 'woocommerce_stock_html', 'filter_woocommerce_stock_html', 10, 3 ); function filter_woocommerce_stock_html( $availability_html, $availability_availability, $variation ) { global $product; if ( has_term( 'Preorder', 'product_tag', $product->ID ) ) : // Define here your text to replace $availability_html = __( 'Say something here', 'woocommerce' ); endif; return $availability_html; }; 

This code has been tested, and I hope this is what you expect to receive.

The code goes in the function.php file of your active child theme (or theme). Or also in any php file plugins.

+4
source

Source: https://habr.com/ru/post/1261316/


All Articles