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
May 29, 2024 at 8:49 am
#48334
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.