Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

WooCommerce - Reviews for product shortcode

lorro Jan 7th, 2016 62 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top