Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelligently detect product search fields and restrict results in Autosuggest #1687

Closed
brandwaffle opened this issue Mar 4, 2020 · 2 comments · Fixed by #1689
Closed

Intelligently detect product search fields and restrict results in Autosuggest #1687

brandwaffle opened this issue Mar 4, 2020 · 2 comments · Fixed by #1689
Assignees
Milestone

Comments

@brandwaffle
Copy link
Contributor

brandwaffle commented Mar 4, 2020

Is your enhancement related to a problem? Please describe.

Currently, WooCommerce product searches show results from the default Autosuggest query, but then a full search (hitting enter to reload the search page) does limit the results as ?post_type=product is passed into the URL and therefore handled by EP properly.
Describe the solution you'd like

Determine when we're on a product search bar when applying Autosuggest, and conditionally limit the search to the product post_type.
Designs

Describe alternatives you've considered

Additional context

This would be a permanent/plugin-wide fix for the issue resolved with custom code in #1684

@Rahmon
Copy link
Contributor

Rahmon commented Apr 10, 2021

A possible workaround here could be to restrict the post type to product when accessing a WooCommerce page:

add_filter(
	'ep_term_suggest_post_type',
	function( $post_types ) {
		if ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) {
			return [ 'product' ];
		}

		return $post_types;
	}
);

@JakePT JakePT self-assigned this Apr 14, 2021
@JakePT
Copy link
Contributor

JakePT commented Apr 15, 2021

@brandwaffle I've updated the PR #1689 to bring it up to date with develop, and improved the handling of post type inputs in the search form.

@Rahmon I think the issue with that approach is that searches for products aren't necessarily coming only from WooCommerce pages. For example, it's common for shops to have a product search form in the header that only searches the shop, and there's no guarantee that WooCommerce pages don't also have a blog search form or similar. The approach in #1689 handles both those cases.

@JakePT JakePT linked a pull request Apr 15, 2021 that will close this issue
6 tasks
@brandwaffle brandwaffle added this to the 3.6.0 milestone Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants