WebDevStudios / wp-search-with-algolia

Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance.

Home Page:https://wordpress.org/plugins/wp-search-with-algolia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help adding WooCommerce price into custom autocomplete template

unitedus-emil opened this issue · comments

Not a bug as such but I'm hoping someone can steer me in the direction of any documentation on how to add price from WooCommerce into the autocomplete suggestions. I have the Pro version of the plugin.

Here's the templating code we use with the Pro plugin to show SKU/prices:

<p>
	<# if ( data.sku ) { #>
	<?php esc_html_e( 'SKU:', 'wp-search-with-algolia-pro' ); ?>
	{{ data.sku }}
	<# } #>

	<# if ( data.price || data.sale_price ) { #>
		<?php esc_html_e( 'Price:', 'wp-search-with-algolia-pro' ); ?>
		<# if ( data.sale_price ) { #>
			<# if ( data.price ) { #>
			<s>{{{ data.price_formatted }}}</s>
			<# } #>
			{{{ data.sale_price_formatted }}}
		<# } #>
		<# if ( ! data.sale_price && data.price ) { #>
			{{{ data.price_formatted }}}
			<# if ( data.max_price ) { #>
				- {{{ data.max_price_formatted }}}
			<# } #>
		<# } #>
	<# } #>
</p>

We echo this out with this hook that we added to the template file:
https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/templates/autocomplete.php#L32-L34

You could do the same in that spot, or if you have a customized autocomplete.php template in the appropriate place that you're wanting. Pretty much everything you see when looking at an indexed object in algolia.com search dashboard, should be available in the templates via the data object.

More information on templating: https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Customize-Templates

Closing as a non issue, but feel free to comment as needed. We'll respond.