Zen Cart Logo
Forums / General Questions / hide specific products without disabling them

hide specific products without disabling them

Views: 669

Results 1 to 5 of 5
9 Jan 2025, 11:36 AM
#1
vmax avatar

vmax

New Zenner

Join Date:
Jun 2018
Location:
uk
Posts:
31
Plugin Contributions:
0

hide specific products without disabling them

ok so im wanting to know if it is possible to hide a specific product or products so it cant be seen on my site but still allow anyone with a direct link to it to still be abler to add to cart and checkout with it

the reason is this, i have a product that is to pay for booking a market pitch however i don't want just anyone to be able to see it, only those who have filled out my booking form via email and i have approved to attend the event and so have received the link to the product page

i previously did this by default on my old website that was set up through weebly and it had 3 statuses for products active, hidden and disabled
active - everyone can see and buy
hidden - didnt show up on the site in search results or in categories but a direct link allowed you to view and add to cart
disabled - self explanatory

is this possible for a person with only novice coding ability but can follow instructions well

zen 2.10
https://www.cjscreativecrafts.com/
PHP Version: 8.3.14

9 Jan 2025, 6:06 PM
#2
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
507
Plugin Contributions:
1

Re: hide specific products without disabling them

You could try this. No programming required.

If you create a new category and disable the category. Then add products to that category. Unless you search specifically for them, they can only be found if you send them a link to the product_id. Thus I have a product that I have achive that I do not want people to see anymore . You can see it here https://innerlightcrystals.co.uk/sales/index.php?main_page=product_info&products_id=3311

So you would have to create the links as above replacing innerlightcrystals.co.uk with your website.

Cavate: they will still appear in searches if people search zen cart for them.

If you are up to a little bit of programming you can exclude categories from the search. Below works for zen cart 2.0.1 and I am pretty sure it will work for 2.1.

Create a file YOURSITE\includes\classes\observers\auto.exclude_search_category.php
put the following code in to it.

<?php
/* 
 * Observers for excluding products with a master category in EXCLUDE_SORT_CATEGORIES from search results.
 */
class zcObserverExcludeSearchCategory extends base {

    public function __construct() {
        $this->attach(
            $this,
            [
                'NOTIFY_SEARCH_WHERE_STRING',
            ]
        );
    }
    protected function updateNotifySearchWhereString(&$class, $eventID, $keywords, &$where_str, $keyword_search_fields) 
    {
        if (!defined('EXCLUDE_SORT_CATEGORIES') || preg_match('#^[0-9 \,]+$#' , EXCLUDE_SORT_CATEGORIES) === 0) {
            return;
        }
        if (!empty($where_str)) {
            $where_str .=  ' AND';
        }
        $where_str .= ' p.master_categories_id NOT IN (' . EXCLUDE_SORT_CATEGORIES . ')';
    }
}

create a second file YOUYSITE\includes\extra_datafiles\search_exclude.php
put the following code in it changing the #### to a comma separated list of the category_id(s) of the categories you want to exclude

<?php
// Enter comma sepersted list of categories to be excluded from search.
define('EXCLUDE_SORT_CATEGORIES','###');

I think that should work!

9 Jan 2025, 11:41 PM
#3
vmax avatar

vmax

New Zenner

Join Date:
Jun 2018
Location:
uk
Posts:
31
Plugin Contributions:
0

Re: hide specific products without disabling them

brittainmark:

You could try this. No programming required.

If you create a new category and disable the category. Then add products to that category. Unless you search specifically for them, they can only be found if you send them a link to the product_id. Thus I have a product that I have achive that I do not want people to see anymore . You can see it here https://innerlightcrystals.co.uk/sales/index.php?main_page=product_info&products_id=3311

So you would have to create the links as above replacing innerlightcrystals.co.uk with your website.

Cavate: they will still appear in searches if people search zen cart for them.

If you are up to a little bit of programming you can exclude categories from the search. Below works for zen cart 2.0.1 and I am pretty sure it will work for 2.1.

Create a file YOURSITE\includes\classes\observers\auto.exclude_search_category.php
put the following code in to it.

<?php /* * Observers for excluding products with a master category in EXCLUDE_SORT_CATEGORIES from search results. */ class zcObserverExcludeSearchCategory extends base { public function __construct() { $this->attach( $this, [ 'NOTIFY_SEARCH_WHERE_STRING', ] ); } protected function updateNotifySearchWhereString(&$class, $eventID, $keywords, &$where_str, $keyword_search_fields) { if (!defined('EXCLUDE_SORT_CATEGORIES') || preg_match('#^[0-9 \,]+$#' , EXCLUDE_SORT_CATEGORIES) === 0) { return; } if (!empty($where_str)) { $where_str .= ' AND'; } $where_str .= ' p.master_categories_id NOT IN (' . EXCLUDE_SORT_CATEGORIES . ')'; } } ``` > > create a second file YOUYSITE\includes\extra_datafiles\search_exclude.php > put the following code in it changing the #### to a comma separated list of the category_id(s) of the categories you want to exclude > > ``` <?php // Enter comma sepersted list of categories to be excluded from search. define('EXCLUDE_SORT_CATEGORIES','###'); ``` > > I think that should work! sounds promising shall try this tomorrow and report back on the results ( or technically lack of results lol :D)
10 Jan 2025, 2:34 PM
#4
vmax avatar

vmax

New Zenner

Join Date:
Jun 2018
Location:
uk
Posts:
31
Plugin Contributions:
0

Re: hide specific products without disabling them

brittainmark:

You could try this. No programming required.

If you create a new category and disable the category. Then add products to that category. Unless you search specifically for them, they can only be found if you send them a link to the product_id. Thus I have a product that I have achive that I do not want people to see anymore . You can see it here https://innerlightcrystals.co.uk/sales/index.php?main_page=product_info&products_id=3311

So you would have to create the links as above replacing innerlightcrystals.co.uk with your website.

Cavate: they will still appear in searches if people search zen cart for them.

If you are up to a little bit of programming you can exclude categories from the search. Below works for zen cart 2.0.1 and I am pretty sure it will work for 2.1.

Create a file YOURSITE\includes\classes\observers\auto.exclude_search_category.php
put the following code in to it.

<?php /* * Observers for excluding products with a master category in EXCLUDE_SORT_CATEGORIES from search results. */ class zcObserverExcludeSearchCategory extends base { public function __construct() { $this->attach( $this, [ 'NOTIFY_SEARCH_WHERE_STRING', ] ); } protected function updateNotifySearchWhereString(&$class, $eventID, $keywords, &$where_str, $keyword_search_fields) { if (!defined('EXCLUDE_SORT_CATEGORIES') || preg_match('#^[0-9 \,]+$#' , EXCLUDE_SORT_CATEGORIES) === 0) { return; } if (!empty($where_str)) { $where_str .= ' AND'; } $where_str .= ' p.master_categories_id NOT IN (' . EXCLUDE_SORT_CATEGORIES . ')'; } } ``` > > create a second file YOUYSITE\includes\extra_datafiles\search_exclude.php > put the following code in it changing the #### to a comma separated list of the category_id(s) of the categories you want to exclude > > ``` <?php // Enter comma sepersted list of categories to be excluded from search. define('EXCLUDE_SORT_CATEGORIES','###'); ``` > > I think that should work! this worked and absolute treat A1!!!! admins should consider adding this to the plugins :clap::bigups::jump::onfire::cheers::bow::bow:
14 Feb 2025, 10:38 AM
#5
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

Re: hide specific products without disabling them

brittainmark:

You could try this. No programming required.

If you create a new category and disable the category. Then add products to that category. Unless you search specifically for them, they can only be found if you send them a link to the product_id. Thus I have a product that I have achive that I do not want people to see anymore . You can see it here https://innerlightcrystals.co.uk/sales/index.php?main_page=product_info&products_id=3311

So you would have to create the links as above replacing innerlightcrystals.co.uk with your website.

Cavate: they will still appear in searches if people search zen cart for them.

If you are up to a little bit of programming you can exclude categories from the search. Below works for zen cart 2.0.1 and I am pretty sure it will work for 2.1.

Create a file YOURSITE\includes\classes\observers\auto.exclude_search_category.php
put the following code in to it.

<?php /* * Observers for excluding products with a master category in EXCLUDE_SORT_CATEGORIES from search results. */ class zcObserverExcludeSearchCategory extends base { public function __construct() { $this->attach( $this, [ 'NOTIFY_SEARCH_WHERE_STRING', ] ); } protected function updateNotifySearchWhereString(&$class, $eventID, $keywords, &$where_str, $keyword_search_fields) { if (!defined('EXCLUDE_SORT_CATEGORIES') || preg_match('#^[0-9 \,]+$#' , EXCLUDE_SORT_CATEGORIES) === 0) { return; } if (!empty($where_str)) { $where_str .= ' AND'; } $where_str .= ' p.master_categories_id NOT IN (' . EXCLUDE_SORT_CATEGORIES . ')'; } } ``` > > create a second file YOUYSITE\includes\extra_datafiles\search_exclude.php > put the following code in it changing the #### to a comma separated list of the category_id(s) of the categories you want to exclude > > ``` <?php // Enter comma sepersted list of categories to be excluded from search. define('EXCLUDE_SORT_CATEGORIES','###'); ``` > > I think that should work! An opportune time for this as I'm implementing search on my site for the first time. Much appreciated!