I'm developing a module for Drupal Commerce - Drupal 7 and I need to get the product image URL from product page but I couldn't find a solution for this.

I'm successfully fetching the product name, title, url but not the its image URL which really bothers me as I am used to WooCommerce where there is a very simple way of getting the image URL.

1 Answer 1


I have found a quick fix for this issue.

$product = commerce_product_load($productId); // loads the product by id
$productImage = drupal_json_encode(file_create_url($product->field_images['und'][0]['uri'])); // gets the main image of the product if it has multiple images and formats the link properly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.