A little bit of background - I'm currently using the Product Pre-Orders for WooCommerce plugin by VillaTheme. Overall it works well for my purposes except for this one thing.
I’d like to make a custom “in stock” message for products that have the product type “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. I should also mention that these are variable products.
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