I am creating a website which is flower shop. Some flowers are seasonally available. Using Advanced Custom Fields plugin, I have added a custom field in Woocommerce product post type (check box) list of months to chose from in which product will be available.
I have been able to disable the add to cart button for the months in which product will not be available using code below:
add_filter('woocommerce_is_purchasable', 'is_available', 10, 2);
function is_available() {
// this is a field added using 'Advance Custom Fields' plugin
$months = get_field('availability');
$currentMonth = date('F');
if(in_array($currentMonth, $months))
return true;
else
return false;
}
The code I'm using works, it removes add to cart button from the related single product page. I would like to add some message, so customers will know why it's not available. How can I do that?
I just need to know how I can add message as well, when the product is not available.