1 回答

TA貢獻1828條經驗 獲得超3個贊
您可以使用如下WC_Product
?get_image()
方法:
echo?$product->get_image(?array('700',?'600'),?array(?"class"?=>?"img-responsive"?),?''?);
然后,在您的代碼中,您可以緩沖所有回顯的自定義代碼以及主產品圖像(在產品描述內容的末尾),如下所示:
// Display description tab when empty
add_filter( 'woocommerce_product_tabs', 'display_description_product_tabs' );
? ? function display_description_product_tabs( $tabs ) {
? ? $tabs['description'] = array(
? ? ? ? 'title'? ? => __( 'Description', 'woocommerce' ),
? ? ? ? 'priority' => 10,
? ? ? ? 'callback' => 'woocommerce_product_description_tab',
? ? );
? ? return $tabs;
}
// Add image to description
add_filter( 'the_content', 'add_product_image_woocommerce_description' );
function add_product_image_woocommerce_description( $content ) {
? ? global $product;
? ? // Single product pages (woocommerce)
? ? if ( is_product() ) {
? ? ? ? ob_start(); // Start buffering
? ? ? ? // HERE your main image
? ? ? ? echo $product->get_image( array('700', '600'), array( "class" => "img-responsive" ), '' );
? ? ? ? $image_content = "";
? ? ? ? // Loop through gallery Image Ids
? ? ? ? foreach( $product->get_gallery_image_ids() as $image_id ) {
? ? ? ? ? ? echo '<img src="'. wp_get_attachment_image_url($image_id, 'full') . '" alt="image_content" width="500" height="600">';
? ? ? ? }
? ? ? ? echo '<p> TEST Image content </p>'; // Testing text
? ? ? ? // Inserting the buffered content after
? ? ? ? $content .= ob_get_clean();
? ? }
? ? return $content;
}
- 1 回答
- 0 關注
- 184 瀏覽
添加回答
舉報