We have a WooCommerce store with a lot of variable products and have added custom text for the stock status. I have successfully changed all the different stock statuses when the attribute is selected, but cannot change the status when there aren't any variable products. That is, "This product is currently out of stock and not available" text.
https://sykleriet.no/produkt/specialized-turbo-levo-comp-alloy/
I've added a fragment to control these statuses; in stock, out of stock and pre-order, thanks for the help here, I've also tried various other fixes and only changed the last one as a standalone fragment, the same as we used for Fragments used together with other fragments - deactivated. Currently, it seems I can't change this text.
Is it possible to add a string in this code or create a separate code for this purpose?
This is the code we use for other code:
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2); function wcs_custom_get_availability( $availability, $_product ) { //Change the in-stock text if ( $_product->is_in_stock() ) { $availability['availability'] = __('På lager', 'woocommerce'); } //Change out-of-stock text if ( ! $_product->is_in_stock() ) { $availability['availability'] = __('Utsolgt', 'woocommerce'); } //Change subscription text if ( $_product->is_on_backorder() ) { $availability['availability'] = __('Bestillingsvare 10-15 dager', 'woocommerce'); } return $availability; }
The code you need to customize the text "This product is currently out of stock and cannot be purchased" is as follows:
Add this code to your current theme’s functions.php file (or a plugin).
woocommerce_out_of_stock_message
Filter hooklocation in WooCommerce code