Search
 
SCRIPT & CODE EXAMPLE
 

PHP

display woocommerce review using specific id

/**
 * WooCommerce Product Reviews Shortcode
 */
 
add_shortcode( 'product_reviews', 'silva_product_reviews_shortcode' );
 
function silva_product_reviews_shortcode( $atts ) {
    
   if ( empty( $atts ) ) return '';
 
   if ( ! isset( $atts['id'] ) ) return '';
       
   $comments = get_comments( 'post_id=' . $atts['id'] );
    
   if ( ! $comments ) return '';
    
   $html .= '<div class="woocommerce-tabs"><div id="reviews"><ol class="commentlist">';
    
   foreach ( $comments as $comment ) {   
      $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
      $html .= '<li class="review">';
      $html .= get_avatar( $comment, '60' );
      $html .= '<div class="comment-text">';
      if ( $rating ) $html .= wc_get_rating_html( $rating );
      $html .= '<p class="meta"><strong class="woocommerce-review__author">';
      $html .= get_comment_author( $comment );
      $html .= '</strong></p>';
      $html .= '<div class="description">';
      $html .= $comment->comment_content;
      $html .= '</div></div>';
      $html .= '</li>';
   }
    
   $html .= '</ol></div></div>';
    
   return $html;
}
Comment

PREVIOUS NEXT
Code Example
Php :: single elimination php code 
Php :: compare strings alphabetically php 
Php :: Breaking of code snippets in CKEditor as result code blocks are empty. 
Php :: encrypt number 
Php :: string replace in php 
Php :: curl outline in laravel 
Php :: why are my css properties not being applied to php file 
Php :: php browser detection script 
Php :: laravel jobs cache file picking old job file 
Php :: laravel soft delete 
Php :: Dorf SMS Plugin 
Php :: php print products with attribute 
Php :: wp_remote_post decode data 
Php :: php month to local language 
Php :: JsonResource withoutWrapping 
Php :: Add a watermark to an existing PDF document 
Php :: data validation of $_POST in php 
Php :: wp register_setting access saved value 
Php :: how to give dynamic value in onlick in php 
Php :: Laravel: validate an integer field that needs to be greater than another 
Php :: laravel class is not recognized in tinker 
Php :: PHP DOMDocument, Unicode problems 
Php :: how to remove public from url in laravel 9 
Php :: composer require laravelcollection 
Php :: provide filter condition in autocomplet field in drupal form using property 
Php :: symfony create form multiple entities 
Php :: how to override category product from seo title and description 
Php :: use middleware in controller to have access session 
Php :: laravel create multiple rows 
Php :: php order array by specific key 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =