问题
I am developing a custom WooCommerce theme and every time I try to retrieve a product's image, all I get is the placeholder image. I've already set the image in the back-end so it should work properly, but it doesn't.
Here is my code:
$args = array(
'post_type' => 'product',
'posts_per_page' => 2
);
$products = get_posts($args);
foreach($products as $the_product) {
$wc_product = new WC_Product($the_product->id);
echo $wc_product->get_image('shop_thumbnail');
}
This is the result:
Could you help me out with this, please?
回答1:
I've actually found the answer to my problem, I used "id" instead of "ID" when accessing the property of the WC_Product object.
来源:https://stackoverflow.com/questions/38276430/woocommerce-shows-the-placeholder-image-when-using-get-image