Php 从Woocommerce中的产品库获取第一个图像的URL
如何获取上载到产品库的第一个图像的URL 我不是说特色形象Php 从Woocommerce中的产品库获取第一个图像的URL,php,wordpress,woocommerce,gallery,src,Php,Wordpress,Woocommerce,Gallery,Src,如何获取上载到产品库的第一个图像的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 attacheme
如有任何建议,我将不胜感激。以下内容将为您提供产品库中的第一个图像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;
}
我们需要更多的细节。如果我们不知道问题出在哪里,我们就帮不了你