Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Check product visibility #5

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

shakethatweight-simon
Copy link

We had some products set to Catalog visibility: Hidden which where made visible by this plugin.
This change will hide anything that isn't set to Shop and Search Results

We had some products set to `Catalog visibility: Hidden` which where made visible by this plugin.
This change will hide anything that isn't set to `Shop and Search Results`
@helgatheviking
Copy link
Collaborator

Hi Simon, thanks for the PR! It's already default behavior to display hidden products as part of a Mix and Match product. Non-visible products do not get a hyperlink to their individual product page. It's pretty common for us to see folks who don't want Widget X and Widget Y showing up in the shop or being sold separately but wanting to sell those as part of a Widget 6 Pack.

So I think this could be a departure for expected functionality. What's your use case like? Could we consider inserted a filter so that you can enable the visible only limitation without impacting how it currently works?

@helgatheviking
Copy link
Collaborator

Simon,

There is already a filter there for modifying the product query. Could you try the following:

function kia_limit_categories_to_visible_products( $args ) {
    $args['visibility'] = 'visible';
}
add_filter( 'wc_mnm_categories_get_cat_content_args', 'kia_limit_categories_to_visible_products' );

Untested, but in theory, that should change your args to only fetch the visible products.

@shakethatweight-simon
Copy link
Author

@helgatheviking Happy to use this filter, but was surprised to see hidden products visible on a page. I'll use the code suggested. Thank you.

@helgatheviking
Copy link
Collaborator

Fair enough. As I explained, some people do intentionally hide products from the catalog to only make them available as part of a Mix and Match product. It doesn't feel like there's really a right answer here, but at least the filter can let us go either way.

@shakethatweight-simon
Copy link
Author

Incase anyone else stumbles on this and wants the same functionality, the code was missing the return line

function kia_limit_categories_to_visible_products( $args ) {
    $args['visibility'] = 'visible';
    return $args;
}
add_filter( 'wc_mnm_categories_get_cat_content_args', 'kia_limit_categories_to_visible_products' );

@helgatheviking
Copy link
Collaborator

FACE PALM! Thanks Simon. I'm not working too hard over the next 2 weeks, but your PR is starting to make more sense to me. While the normal MNM process allows you to actively select which hidden products you wish to display, it's not quite the same here since this opts you in to offering all the hidden products. I'm starting to think you might be right and that the snippet could then exist to undo the visible restriction.

I'll let it marinate since with the above snippet you have a workaround for the time being.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants