Creating Exclusive Products
-
Hi there,
Is there any way of creating an exclusive product that is only available in a bundle and is not accessible any other way?
I have made a product and added it to a ‘Bundle Exclusives’ category.
I have hidden the category with:
// 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( 6845 ); // 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; }and, have changed the display from £0 to Free! with:
function wpglorify_price_free_zero_empty( $price, $product ) { if ( $product->get_price() == 0 ) { if ( $product->is_on_sale() && $product->get_regular_price() ) { $regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) ); $price = wc_format_price_range( $regular_price, __( 'Free!', 'woocommerce' ) ); } else { $price = '<span class="amount">' . __( 'Free!', 'woocommerce' ) . '</span>'; } } return $price; } add_filter( 'woocommerce_get_price_html', 'wpglorify_price_free_zero_empty', 10, 2 );Is there any way of hiding the exclusive product from the store? It appears on the search and shop pages. You cannot change the visibility to ‘hidden’ on the product because then, it doesn’t allow users to purchase the product.
/JJ
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Creating Exclusive Products’ is closed to new replies.