daily pastebin goal
13%
SHARE
TWEET

WooCommerce - Reviews for product shortcode

lorro Jan 7th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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