Thanks @wpclever
I have built upon the code and issue I was having. I have disabled the purchase (with your code), then removed certain features (add to cart button, price, social share, category list, reviews) for products within the ‘Bundle Exclusives’ category. Finally, I have hidden the ‘Bundle Exclusives’ category. Bit of a weird fix. Would love to see exclusive products implemented in WooCommerce or the Product Bundles plugin!
Code
// DISABLE PURCHASE
add_filter( 'woocommerce_add_to_cart_validation', 'woosb_prevent_exclusive_products', 10, 2 );
function woosb_prevent_exclusive_products( $passed, $product_id ) {
$exclusive_products = array( 6292, 6291, 6290, 6286, 6285, 6284, 6279, 6278, 6277 ); // fill your exclusive products ID here
if ( in_array( $product_id, $exclusive_products, false ) ) {
wc_add_notice( esc_html__( 'This is an exclusive product only available in bundles!', 'woo-product-bundle' ), 'error' );
return false;
}
return $passed;
}
// DISABLE ADD TO CART BUTTON, PRICE, SOCIAL SHARE AND CATEGORY LIST ON BUNDLE EXCLUSIVE CATEGORY
add_action('woocommerce_single_product_summary', 'remove_product_description_add_cart_button', 1 );
function remove_product_description_add_cart_button() { // function for deleting ...
// Set category ID
$categories = array('bundle-exclusives');
//Feature removal
if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
}
}
// HIDE BUNDLE EXCLUSIVE CATEGORY
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() &&is_shop() ) {
foreach( $terms as $key => $term ) {
if ( !in_array( $term->slug, array( 'bundle-exclusives', 'uncategorized' ) ) ) { //pass the slug name here
$new_terms[] = $term;
}}
$terms = $new_terms;
}
return $terms;
}
Screenshots:
Normal product: http://prntscr.com/12l3zr6
Bundle exclusive product: http://prntscr.com/12l40fs
Thanks for your help,
Best, /JJ