check if woo product has images

PHOTO EMBED

Fri May 13 2022 08:06:44 GMT+0000 (Coordinated Universal Time)

Saved by @McDev #php

function dotirating_function( $attr ) {
91
  $args = shortcode_atts( array('id' => '',), $attr );
92
    
93
    $product_id = $args['id'];
94
    $product = new WC_product($product_id);
95
    $attachment_ids = $product->get_gallery_image_ids();
96
    
97
    if ( ! empty($attachment_ids) ) :
98
    return wp_get_attachment_image($attachment_ids[0], 'large');
99
endif;
100
    
101
}
102
​
103
add_shortcode('dotirating', 'dotirating_function');
content_copyCOPY

https://wordpress-543613-2502748.cloudwaysapps.com/wp-admin/theme-editor.php?file