"Available In Store Only" Products by Category
Lets customers browse products from chosen categories online but removes the Add to Cart button and shows an "available in store only" message instead.
Opens WPIDE on
Code
$wpide_store_only = array(
'categories' => array( 'furniture' ), // Category slugs.
'message' => 'Available in our showroom only. Call us to reserve one.', // Shown instead of Add to Cart.
);
$wpide_store_only_match = function ( $product ) use ( $wpide_store_only ) {
$id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
return has_term( $wpide_store_only['categories'], 'product_cat', $id );
};
add_filter( 'woocommerce_is_purchasable', function ( $purchasable, $product ) use ( $wpide_store_only_match ) {
return $purchasable && ! $wpide_store_only_match( $product );
}, 10, 2 );
add_action( 'woocommerce_single_product_summary', function () use ( $wpide_store_only, $wpide_store_only_match ) {
global $product;
if ( $product instanceof WC_Product && $wpide_store_only_match( $product ) ) {
printf( '<p class="wpide-store-only">%s</p>', esc_html( $wpide_store_only['message'] ) );
}
}, 31 );
add_filter( 'woocommerce_product_add_to_cart_text', function ( $text, $product ) use ( $wpide_store_only_match ) {
return $wpide_store_only_match( $product ) ? 'View details' : $text;
}, 10, 2 );
Notes
Products stay visible with their price; add your opening hours or address to the message.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.