I'm trying to hide the stock status on the single product page only when a product is tagged with 'preorder'.
So far I've added below mentioned code to my functions.php to change the add to cart button text for this specific tag. Any idea what code should/could be added in order 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;
}
You should try woocommerce_stock_html
filter hook for this purpose:
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 is tested, and I hope is what you are expecting to get.
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With