Skip to main contentSkip to footer

Aelia has a Prices by Country for WooCommerce plugin, which can adjust prices based on customer country and hide products unavailable in a specific country. Jason James shared a function that makes Relevanssi hide unavailable products in search:

add_filter( 'relevanssi_post_ok', 'relevanssi_aelia_compatibility', 10, 2 );
function relevanssi_aelia_compatibility( $post_ok, $post_id ) {
	$post       = get_post( $post_id ); 
	$post_type  = $post->post_type; 
	$product_id = $post->ID;

	if ( 'product' === $post_type && function_exists( 'wc_get_product' ) ) {
		// Get the product object.
		$product = wc_get_product( $product_id );

		// Check if the product is purchasable.
		if ( $product && ! $product->is_purchasable() ) {
			$post_ok = false;
		}
	} 
	return $post_ok;
}

This function uses the relevanssi_post_ok filter hook to control which posts are included in the search and the $product->is_purchasable() function to see if the product can be shown.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Avada

Avada is one of the most popular WordPress themes on the market. All post types are not found Avada has search settings, including a list of post types to show in the results. If your Avada search is not showing all post types, attachments or user profiles, the problem is…

Setting post_type to page doesn’t work

For some reason setting the post_type query variable to page doesn’t have the desired effect. Other post types (post, custom post types) work, but page doesn’t do anything. This is not a Relevanssi bug, but a WordPress feature (see this trac ticket). If the user inputs a bad value to…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed