daily pastebin goal
32%
SHARE
TWEET

WooCommerce - Reviews for product shortcode

lorro Jan 7th, 2016 60 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
Top