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 关注
- 138 浏览
添加回答
举报