Products attributes in the resultbox

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Products attributes in the resultbox

This topic contains 9 replies, has 2 voices, and was last updated by skempenaar skempenaar 4 years, 2 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #26038
    skempenaar
    skempenaar
    Participant

    Hi 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.

    Attachments:
    You must be logged in to view attached files.
    #26042
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #26043
    skempenaar
    skempenaar
    Participant

    Thx works like a charm!. what if i want to have a separator between it but only displayed when there is content.

    Attachments:
    You must be logged in to view attached files.
    #26046
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You 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>]

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #26047
    skempenaar
    skempenaar
    Participant

    im sorry did look that up in the docs. thx!!!!

    #26048
    skempenaar
    skempenaar
    Participant

    allright one last question:) are woocommerce star reviews even possible?

    #26054
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You 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">&nbsp;</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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #26059
    skempenaar
    skempenaar
    Participant

    yet again! works like a charm:D

    #26060
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #26061
    skempenaar
    skempenaar
    Participant

    done!

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Products attributes in the resultbox’ is closed to new replies.