从 Woocommerce 的产品库中获取第一张图片的 URL
Get the URL of the first image from the product gallery in Woocommerce
如何获取上传到产品图库的第一张图片的 URL?
我说的不是特色图片。
如果有任何建议,我将不胜感激。
以下将为您提供产品图库中的第一张图片 Url:
global $post, $product;
if( is_a($product, 'WC_Product'))
$product = wc_get_product($post->ID);
$product = wc_get_product(40);
// Get the array of the gallery attachement IDs
$attachment_ids = $product->get_gallery_image_ids();
if( sizeof($attachment_ids) > 0 ){
$first_attachment_id = reset($attachment_ids);
$link = wp_get_attachment_image_src( $first_attachment_id, 'full' )[0];
// Output
echo $link;
}
如何获取上传到产品图库的第一张图片的 URL?
我说的不是特色图片。
如果有任何建议,我将不胜感激。
以下将为您提供产品图库中的第一张图片 Url:
global $post, $product;
if( is_a($product, 'WC_Product'))
$product = wc_get_product($post->ID);
$product = wc_get_product(40);
// Get the array of the gallery attachement IDs
$attachment_ids = $product->get_gallery_image_ids();
if( sizeof($attachment_ids) > 0 ){
$first_attachment_id = reset($attachment_ids);
$link = wp_get_attachment_image_src( $first_attachment_id, 'full' )[0];
// Output
echo $link;
}