In order to allow adding Custom Product Builder products to cart we need to generate custom products that hold variants. These products can appear in the search results and collection pages.
All those auto generated products have product_type="cpb_ordered".
You can filter them out by following these simple steps:
Hide cpb_ordered products from search results:
Open template file called "snippet/search-form.liquid".
Add to the very top of the file copy paste this line of code:
{% assign clean_search_terms = search.terms | remove: " -product_type:cpb_ordered -product_type:cpb_variants" %}
Find this code in the file:
<h1 class="h2">
<span class="visually-hidden">{{ 'general.search.heading' | t: count: search.results_count }}:</span>
{{ 'general.search.results_with_count' | t: terms: search.terms, count: search.results_count }}
</h1>
Replace it with the following code:
<h1 class="h2">
<span class="visually-hidden">{{ 'general.search.heading' | t: count: search.results_count }}:</span>
{{ 'general.search.results_with_count' | t: terms: clean_search_terms, count: search.results_count }}
</h1>
Find code for the search form::
<form action="{{ routes.search_url }}" method="get" role="search" class="search">
<div aria-live="polite" class="form-message form-message--error search-result-error-message hide" data-search-error-message>
<ul id="error-search-form">
<li>{{ 'general.search.empty_search_message' | t }}</li>
</ul>
</div>
<div class="input-group">
<input type="search"
id="SearchInput"
class="input-group__field search__input"
name="q"
value="{{ search.terms | escape }}"
placeholder="{{ 'general.search.placeholder' | t }}"
aria-label="{{ 'general.search.placeholder' | t }}"
>
<span class="input-group__btn">
<button id="SearchResultSubmit" class="btn search__submit" type="submit">{{ 'general.search.submit' | t }}</button>
</span>
</div>
</form>
Replace that code with the following code:
<form action="{{ routes.search_url }}" method="get" role="search" class="search"
onsubmit="this.q.value=document.getElementById('SearchInput').value+' -product_type:cpb_ordered -product_type:cpb_variants'">
<div aria-live="polite" class="form-message form-message--error search-result-error-message hide" data-search-error-message>
<ul id="error-search-form">
<li>{{ 'general.search.empty_search_message' | t }}</li>
</ul>
</div>
<div class="input-group">
<input type="search"
id="SearchInput"
class="input-group__field search__input"
value="{{ clean_search_terms | escape }}"
placeholder="{{ 'general.search.placeholder' | t }}"
aria-label="{{ 'general.search.placeholder' | t }}"
>
<input type="hidden" name="q" value="">
<span class="input-group__btn">
<button id="SearchResultSubmit" class="btn search__submit" type="submit">{{ 'general.search.submit' | t }}</button>
</span>
</div>
</form>
Edit other search forms:
Find input with attribute { name="q" }.
Remove attribute { name="q" } .
Add attribute { id="yourSearchId" } if this input does not have attribute called id.
Replace this line:
value="{{ search.terms | escape }}"
with:
value="{{ search.terms | remove: " -product_type:cpb_ordered -product_type:cpb_variants" | escape }}"
Add the value line right before the <input>
<input type="hidden" name="q" value="">
Add to the search form next attribute:
onsubmit="this.q.value=document.getElementById('yourSearchId').value+' -product_type:cpb_ordered -product_type:cpb_variants'"
Add shopify filter
remove: " -product_type:cpb_ordered -product_type:cpb_variants"
to any place where you can see search.terms.
Hide auto generated products from collections and product list pages.
All those auto generated products have product_type="cpb_ordered".
If you wish remove it from your collection page. Go to Online Store -> Products -> Collection.
Find in the collections list your collection. Open for edit and add condition:
product_type is not equal to cpb_ordered.
To hide those products from collections/all follow these steps:
Go to Online Store -> Products -> Collection. Click the button "Create collection".
Create new collection with title "All". Set condition type "Automated". Add follow condition "product_type is not equal to cpb_ordered". To save those collection.
Remove auto-generated products from the Global Settings
You can also remove all outdated auto-generated products from your store both just a few clicks.
1. Open CPB App.
2. Get to the "Global Settings" and scroll down to the "Delete Auto-Generated Products" line.
3. Set a period of time and press "Delete". All Autot-generated products created in that period of time will be automatically removed from your inventory.
Comments
0 comments
Please sign in to leave a comment.