WooCommerce 在使用 get_image() 时显示占位符图像 [英] WooCommerce shows the placeholder image when using get_image()
本文介绍了WooCommerce 在使用 get_image() 时显示占位符图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个自定义的 WooCommerce 主题,每次我尝试检索产品的图像时,我得到的只是占位符图像.我已经在后端设置了图像,所以它应该可以正常工作,但它没有.
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.
这是我的代码:
$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');
}
结果如下:
你能帮我解决这个问题吗?
Could you help me out with this, please?
推荐答案
我实际上找到了问题的答案,我在访问 WC_Product 对象的属性时使用了id"而不是ID".
I've actually found the answer to my problem, I used "id" instead of "ID" when accessing the property of the WC_Product object.
这篇关于WooCommerce 在使用 get_image() 时显示占位符图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文