WooCommerce shows the placeholder image when using get_image()

不想你离开。 提交于 2020-01-17 06:17:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!