Custom “in stock” message
-
Hello,
I’d like to make a custom “in stock” message for products that have the “pre-order” box checked.
Currently I have implemented the below solution via php however it is cumbersome as it requires manually entering/updating the product ids.
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 10, 2); function wcs_custom_get_availability( $availability, $_product ) { $product_ids = array(3831, 3832); // custom if (in_array( $_product->get_id(), $product_ids ) ) { $availability['availability'] = sprintf( __('Available for Pre-Order', 'woocommerce'), $_product->get_stock_quantity()); } // Out of stock if ( ! $_product->is_in_stock() ) { $availability['availability'] = __('Out of Stock', 'woocommerce'); } return $availability; }
I would prefer a code solution that is able to automatically recognize when a product is designated as a pre-order item and update the “in stock” text accordingly.
Any updates you can make to my code to function as described are greatly appreciated.
Thanks in advance,
Ryan
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom “in stock” message’ is closed to new replies.