WooCommerce 在使用 get_image() 时显示占位符图像
WooCommerce shows the placeholder image when using get_image()
我正在开发自定义 WooCommerce 主题,每次我尝试检索产品图片时,我得到的只是占位符图片。我已经在后端设置了图像,所以它应该可以正常工作,但是没有。
这是我的代码:
$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');
}
这是结果:
你能帮我解决这个问题吗?
我实际上找到了问题的答案,我在访问 WC_Product 对象的 属性 时使用 "id" 而不是 "ID"。
我正在开发自定义 WooCommerce 主题,每次我尝试检索产品图片时,我得到的只是占位符图片。我已经在后端设置了图像,所以它应该可以正常工作,但是没有。
这是我的代码:
$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');
}
这是结果:
你能帮我解决这个问题吗?
我实际上找到了问题的答案,我在访问 WC_Product 对象的 属性 时使用 "id" 而不是 "ID"。