For WooCommerce I have a custom metabox that sets products to unavailable if ticked.
The code below removes the add to cart button if a product is set to unavailable:
// Remove add to cart button if product is set to unavailable
function bja_replace_add_to_cart_button($purchasable, $product) {
$product_unavailable = get_post_meta($product->get_id(), '_product_unavailable', true);
if ($product_unavailable === 'on') {
$purchasable = false;
}
return $purchasable;
}
add_filter('woocommerce_is_purchasable', 'bja_replace_add_to_cart_button', 10, 2);
In addition to removing the add to cart button, I'd like to add a line of text below the short description, to indicate the product is unavailable. For that I have the following code:
// Add text below short description
function bja_product_unavailable_text( $content ) {
$content .= '<div class="bja_product_unavailable">This product is unavailable.</div>';
return $content;
}
add_filter('woocommerce_short_description', 'bja_product_unavailable_text', 10, 2);
Both pieces of code work, but now I'd like to run the second piece only if the first one runs. What would be a good way of doing that?