在 WooCommerce 中获取变体图像缩略图的 URL [英] Get URL of variation image thumbnails in WooCommerce
本文介绍了在 WooCommerce 中获取变体图像缩略图的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码来获取特定产品的每个变体的图像:
I'm using the following code to grab the image of every variation for a particular product:
$product = new WC_Product_Variable( $product_id );
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
echo "<img src=" . $variation['image']['url'] .">";
}
这将返回完整尺寸的图像.
This returns the full size image.
谁能告诉我如何修改它以返回缩略图"网址?(或任何其他尺寸)
我确定这是一个相当简单的更改,但我就是想不通.
I'm sure it's a fairly simple change but I just can't figure it out.
推荐答案
使用 thumb_src 而不是 url.
Use thumb_src instead of url.
$product = new WC_Product_Variable( $product_id );
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
echo "<img src=" . $variation['image']['thumb_src'] .">";
}
这篇关于在 WooCommerce 中获取变体图像缩略图的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文