Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove stock status for specific product tag - Woocommerce

Tags:

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;
}
like image 212
Wim Avatar asked Dec 15 '16 09:12

Wim


1 Answers

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.

like image 108
LoicTheAztec Avatar answered Oct 11 '22 14:10

LoicTheAztec