Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode( 'product_rating', 'bb_show_product_rating_based_on_id' );
- function bb_show_product_rating_based_on_id( $atts ) {
- $atts = shortcode_atts( array(
- 'id' => '',
- ), $atts, 'product_rating' );
- if ( isset($atts['id']) && $atts['id'] > 0 ):
- // get WC_Product Object
- $product = wc_get_product( $atts['id'] );
- // product average rating (how many stars the product has)
- $average = $product->get_average_rating();
- endif;
- if ( isset($average) ) :
- return wc_get_rating_html($average);
- endif;
- }
Add Comment
Please, Sign In to add comment