SearchWP Blog

WordPress Tutorials, Tips, and Resources to Help Grow Your Business

How to make WooCommerce product documents searchable

WooCommerce gives you the flexibility to sell almost anything online, be it physical or digital products.

However, if you’re offering downloadable content or products that have documentation, such as manuals, guides, or specifications, then it can be challenging for your customers to find them if they’re not made searchable.

This is where SearchWP comes into play. By making these documents searchable in WooCommerce, you can enhance the user experience and potentially increase conversions.

In this article, we’ll show you how to use make WooCommerce product documents searchable.

Why Make WooCommerce Product Documents Searchable?

Offering product documentation in WooCommerce provides a lot of benefits. You can help customers learn about the products, how it functions, what features it offers, and resolves their queries.

However, if users can’t find these documents on your online store, then they’ll be left frustrated and might exit your website.

That’s why making WooCommerce product document searchable improves overall user experience. Customers can quickly find product-related documents without navigating through numerous pages.

It also helps increase engagement, as easier access to relevant documents can lead to more time spent on your site.

This in turn boost conversions on your WooCommerce store. Providing valuable information at the right time can facilitate purchase decisions and encourage customers to buy your products.

Similarly, it also reduces support requests as customers can find answers to their questions directly from the documents.

That said, let’s look at how to make WooCommerce product documents searchable in WooCommerce.

Enable WooCommerce Product Document Search

The default search feature in WooCommerce is quite limited and doesn’t allow you to search product documents. However, you can change that with SearchWP.

It is the best search plugin for WordPress, and it easily integrates with WooCommerce.

With SearchWP, it’s possible to index the content of those documents and make them searchable for your customers. Besides that, you also get features like customizable algorithm, search analytics, live search, and more.

To start, simply visit the SearchWP website and click the ‘Get SearchWP Now’ button to create a new account.

SearchWP

The next thing you’ll need to do is download the SearchWP plugin.

Head to your account area and switch to the ‘Downloads’ tab. From here, you can click the Download SearchWP button and save the plugin file to your computer.

Download SearchWP plugin from account area

After that, you will need to install and activate the SearchWP plugin on your site. If you need help, then please this guide on how to install the WordPress plugin step-by-step guide.

Upon activation, a SearchWP welcome screen and setup wizard will appear in your WordPress dashboard. Go ahead and click the ‘Start Onboarding Wizard’ button and follow the onscreen instructions.

Onboarding wizard SearchWP

In order to make WooCommerce product documents searchable, you’ll need to install the WooCommerce extension.

Simply go to SearchWP » Extensions from the WordPress dashboard and navigate to the WooCommerce Integration.

Install WooCommerce extension

From here, you can click the ‘Install’ button. Wait a few moments, and you’ll see it successfully installed.

SearchWP will now have access to all WooCommerce products on your site.

Creating Custom SearchWP Customization Plugin

Next, you will need to make product documents searchable in WooCommerce by customizing the behavior of SearchWP.

To do that, you can create a custom plugin called SearchWP Customizations plugin and add hooks.

Hooks are functions that integrate with SearchWP and allow unique customizations without the need to edit the core plugin files. Plus, your new features will remain in place when you update SearchWP or your website theme.

The benefit to this approach is that it will index content of WooCommerce Downloads without exposing the entire asset.

Note: For this approach to work, please ensure that the product documents are uploaded to the WordPress Media Library of your site.

To start, you will need to create your own plugin. Simply open a Notepad or TextEdit file on your computer and enter the following code:

<?php
/*
Plugin Name: SearchWP Customizations
Description: Customizations for SearchWP
Version: 1.0.0
*/

// Add all hooks and custom code here.

After that, you can save the file and name it ‘SearchWP Customizations’.

It will look something like this:

Create a custom SearchWP plugin

After that, you will need to add the hook in the plugin file you just created.

Simply enter the following code under the ‘Add all hooks and custom code here’ section.

<?php

// Tell SearchWP to parse WooCommerce Downloadable Product downloads for document content.
// The content will be extracted from downloadable documents where possible and stored
// in SearchWP's index as a Custom Field with a label of "SearchWP WooCommerce Download Content"
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) {
	if ( 'post.product' !== $entry->get_source()->get_name() || ! class_exists( 'WC_Product' ) ) {
		return $data;
	}

	$product   = new \WC_Product( $entry->get_id() );
	$downloads = $product->get_downloads();

	if ( empty( $downloads ) ) {
		return $data;
	}

	// WooCommerce only stores a hashed ID, the filename, and the URL to the file
	// but we need to retrieve the Media library ID for each downloadable file.
	$download_content = [];
	$upload_dir = wp_upload_dir();
	foreach ( $downloads as $key => $download ) {
		$relative_file_location = str_replace( trailingslashit( $upload_dir['baseurl'] ), '', $download['data']['file'] );

		// We can use the relative file location to retrieve the post ID we need to parse the PDFs.
		$file_id = get_posts( [
			'post_type'   => 'attachment',
			'post_status' => 'inherit',
			'fields'      => 'ids',
			'meta_query'  => [ [
					'key'   => '_wp_attached_file',
					'value' => $relative_file_location,
			], ],
		] );

		if ( ! empty( $file_id ) ) {
			$download_content[] = \SearchWP\Document::get_content( get_post( $file_id[0] ) );
		}
	}

	$data['meta']['swp_wc_doc_content'] = \SearchWP\Utils::tokenize( $download_content );

	return $data;
}, 20, 2 );

// Add "SearchWP WooCommerce Download Content" as an available option.
add_filter( 'searchwp\source\attribute\options', function( $keys, $args ) {
	if ( $args['attribute'] !== 'meta' ) {
		return $keys;
	}

	$content_key = 'swp_wc_doc_content';

	if ( ! in_array(
		$content_key,
		array_map( function( $option ) { return $option->get_value(); }, $keys )
	) ) {
		$keys[] = new \SearchWP\Option( $content_key, 'SearchWP WooCommerce Download Content' );
	}

	return $keys;
}, 20, 2 );

Now go ahead and save the file on your computer. You can also view our knowledge base document for more information. 

If you’re not comfortable handling code on your website, then you can also use WPCode. It is the best code snippet plugin for WordPress and makes it super easy to manage and insert custom code on your website.

It should look something like this:

Enter hook for product documents

Next, you’ll need to add the file to the ‘plugins’ folder of your website. You can access your website files and folders by using a file transfer protocol (FTP) client or file manager in the cPanel of your hosting provider.

For this tutorial, we will use an FTP service, like FileZilla. If you need help getting started, then please see this guide on how to use FTP to upload files to WordPress.

After you’ve connected to your website, simply head to the public_html » wp-content » plugins folder under the Remote site column.

Head to plugin folder of your site

Next, you can navigate to the SearchWP Customizations plugin under the Local site column.

Go ahead and right-click the file and then select the ‘Upload’ option.

Upload SearchWP customizations plugin

Once that file is saved, you’ll need to navigate to the Plugins » Installed Plugins page of your WordPress installation.

From here, you can scroll down to the ‘SearchWP Customizations’ plugin and click the ‘Activate’ button.

Activate SearchWP customizations plugin

After activating the plugin, you can now make WooCommerce product documents searchable on your site.

Configure Search Engine to Search WooCommerce Product Documents

Now, you need to customize the SearchWP engine to make product documents searchable in WooCommerce.

To do that, simply visit the SearchWP » Algorithm page from your WordPress dashboard. From here, you can click the ‘Sources & Settings’ button.

Edit or add new search engines in WordPress

After that, you’ll see a popup with different sources, like posts, pages, and media.

If you want WooCommerce products to be searchable, then make sure to select Products as one of the sources.

Select products as sources

Simply click the ‘Done’ button when you’re finished.

Next, you can scroll down to the ‘Products’ section in the search engine settings. The plugin will index the title, content, slug, and excerpt of products.

However, to include documentations, you’ll need to click the ‘Add/Remove Attributes’ button.

Add and remove attributes of products

After that, you will need to enter a new custom field in SearchWP engine.

Simply enter and select ‘SearchWP WooCommerce Download Content’ in the Custom Fields dropdown.

Select WooCommerce download content

Next, you can click the ‘Done’ button.

Pro Tip: To ensure search accuracy, you can disable ‘Media’ as source from the search engine. That’s because product documents will already be added to the Product source as an attribute.

After that, you can click the ‘Save’ button at the top and then click the ‘Rebuild Index’ button.

Save and rebuild index

That’s it, you’ve successfully made WooCommerce product documents searchable on your site.

Simply visit your eCommerce store to test the search functionality and lookup different documentations.

Document search preview

We hope this article helped you learn how to make WooCommerce product documents searchable. You may also want to see our guide on how to search by SKU in WooCommerce and how to add WooCommerce product search to header.

Ready to create a better and more personalized WordPress search experience? Get started with SearchWP today!

author avatar
Aazim Akhtar

Create a Better WordPress Search Experience Today

Never lose visitors to unhelpful search results again. SearchWP makes creating your own smart WordPress search fast and easy.

Get SearchWP Now
Multiple Search Engines Icon