Guest User

Untitled

a guest
Dec 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. add_shortcode( 'product_rating', 'bb_show_product_rating_based_on_id' );
  2. function bb_show_product_rating_based_on_id( $atts ) {
  3.  
  4. $atts = shortcode_atts( array(
  5. 'id' => '',
  6. ), $atts, 'product_rating' );
  7.  
  8. if ( isset($atts['id']) && $atts['id'] > 0 ):
  9. // get WC_Product Object
  10. $product = wc_get_product( $atts['id'] );
  11.  
  12. // product average rating (how many stars the product has)
  13. $average = $product->get_average_rating();
  14. endif;
  15.  
  16. if ( isset($average) ) :
  17. return wc_get_rating_html($average);
  18. endif;
  19. }
Add Comment
Please, Sign In to add comment