Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Products attributes in the resultbox
- This topic has 9 replies, 2 voices, and was last updated 6 years, 3 months ago by
skempenaar.
-
AuthorPosts
-
February 28, 2020 at 11:41 am #26038
skempenaar
ParticipantHi i would like to display some products attributes in the result box. this because we have some products with the same title. this because 1 is a paperback the other is an e-book. i’ve tried to include {pa_bindwijze}. but this did not do the trick.
February 28, 2020 at 12:40 pm #26042Ernest Marcinko
KeymasterHi,
Some product attributes might be stored as taxonomy terms, try this syntax instead:
{__tax_pa_bindwijze}
For all the details and usage of those fields you can check the Advanced Title and Content fields documentation.February 28, 2020 at 2:02 pm #26043skempenaar
ParticipantThx works like a charm!. what if i want to have a separator between it but only displayed when there is content.
February 28, 2020 at 2:18 pm #26046Ernest Marcinko
KeymasterYou are welcome!
Use the conditional bracket syntax, in the previous linked documentation.
[{__tax_pa_bindwijze} | {__tax_pa_druk}<br>]or:
{__tax_pa_bindwijze}[ | {__tax_pa_druk}<br>]February 28, 2020 at 2:31 pm #26047skempenaar
Participantim sorry did look that up in the docs. thx!!!!
February 28, 2020 at 2:39 pm #26048skempenaar
Participantallright one last question:) are woocommerce star reviews even possible?
February 28, 2020 at 4:10 pm #26054Ernest Marcinko
KeymasterYou are welcome 🙂
Well, there was a custom-coded solution that worked a long time ago. I am not sure if that is still the case, but it is worth a try. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter( 'asp_results', 'asp_add_woo_ratings', 1, 1 ); function asp_my_print_stars( $id ){ global $wpdb; $count = $wpdb->get_var(" SELECT COUNT(meta_value) FROM $wpdb->commentmeta LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE meta_key = 'rating' AND comment_post_ID = $id AND comment_approved = '1' AND meta_value > 0 "); $rating = $wpdb->get_var(" SELECT SUM(meta_value) FROM $wpdb->commentmeta LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE meta_key = 'rating' AND comment_post_ID = $id AND comment_approved = '1' "); $out = ''; if ( $count > 0 ) { $average = number_format($rating / $count, 2); ob_start(); ?> <div class="woocommerce"> <div itemprop="reviewRating" itemscope="" itemtype="http://schema.org/Rating" class="star-rating" title="<?php sprintf(__('Rated %s out of 5', 'woocommerce'), $average); ?>"> <span style="width:<?php echo ($average*20); ?>%"><strong itemprop="ratingValue"> </strong></span> </div> </div> <?php $out = ob_get_clean(); } return $out; } function asp_add_woo_ratings( $results ) { foreach ($results as $k=>&$v) { if ( $v->content_type == 'pagepost' && in_array($v->post_type, array('product', 'product_variation')) ) { $v->content .= asp_my_print_stars($v->id); } } unset($v); return $results; }February 28, 2020 at 4:57 pm #26059skempenaar
Participantyet again! works like a charm:D
February 28, 2020 at 4:58 pm #26060Ernest Marcinko
KeymasterYou cannot access this content.
February 28, 2020 at 5:00 pm #26061skempenaar
Participantdone!
-
AuthorPosts
- The topic ‘Products attributes in the resultbox’ is closed to new replies.