This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: CSS classes based on Woo product type in the result box

Home Forums Product Support Forums Ajax Search Pro for WordPress Support CSS classes based on Woo product type in the result box Reply To: CSS classes based on Woo product type in the result box

#48334
Ernest MarcinkoErnest Marcinko
Keymaster

Yes, exactly like that – but that would not help either, because the post object does not contain the metadata information. The post meta needs to be fetched either way separately.

According to the docs, somethins like this is the way:

add_filter('asp_result_css_class', function($css, $id, $result){
	if (isset($result->post_type) && $result->post_type == 'product') {
		$product = wc_get_product($id);
		if ( $product->is_type('external') ) {
			$css .= ' my-css-class-name';
		}
	}
	return $css;
});

But if the is_type function can be stubbed with post meta check for the product type, then it might be a bit more efficient, as the wc_get_product is then not neccessary, saving some queries. I’m not sure how WooCommerce stores the types, but I guess it’s post metadata, so it’s probably doable.