Advertisement
lorro

WooCommerce - Reviews for product shortcode

Jan 7th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2. // show approved reviews for product shortcode
  3. // usage: [show_reviews product_id="1234"]
  4. // code goes in functions.php for your child theme
  5.  
  6. add_shortcode('show_reviews', 'show_reviews');
  7. function show_reviews($attributes) {
  8.   $a = shortcode_atts( array('product_id' => 'product_id'), $attributes );
  9.   $product_id = absint($a['product_id']);
  10.   if (!$product_id) return;
  11.   $args = array ('post_id' => $product_id, 'status' => 'approve');
  12.   $comments = get_comments( $args );
  13.   return wp_list_comments( array( 'callback' => 'woocommerce_comments', 'echo' => false ), $comments);
  14. } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement