Woocommerce 分组产品图片 [英] Woocommerce Grouped Product Images

查看:41
本文介绍了Woocommerce 分组产品图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在分组产品的名称和价格旁边添加产品缩略图.目前,一个父产品包括 20 个左右的子(分组)产品,默认情况下,页面仅在列表底部显示数量选择器、产品名称、价格和添加到购物车按钮.所有产品都列在一张大桌子下面,我想为每个单独的产品添加一张单独的产品图片.

目前,通过编辑/single-product/add-to-cart/grouped.php 产品文件,我设法通过在产品标题php后的DIV:

<?php if ( has_post_thumbnail( $post_id ) ) { ?><a itemprop="image" href="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post_id ) ); ?>"class="zoom" rel="thumbnails" title="<?php echo get_the_title( get_post_thumbnail_id( $post_id ) ); ?>"><?php echo get_the_post_thumbnail( $post_id, apply_filters( 'grouped_product_large_thumbnail'shop_thumbnail'), 数组('标题' =>get_the_title( get_post_thumbnail_id( $post_id ) ),) );?></a><?php } ?>

我知道这个代码只是从捆绑的产品图片中复制的,但它是我得到的最接近的.你可以在这里看到我的意思的例子:

http://hallmark.digitalstorm.co.uk/product/luxor-custom-built-arrangement/

任何帮助将不胜感激,因为我知道我必须非常接近.

解决方案

这是您要查找的代码:

add_action('woocommerce_grouped_product_list_before_price', 'woocommerce_grouped_product_thumbnail');功能 woocommerce_grouped_product_thumbnail( $product ) {$image_size = array( 20, 20 );//数组(宽度,高度)图像大小(以像素为单位)$attachment_id = get_post_meta( $product->id, '_thumbnail_id', true );?><td class="标签"><?php echo wp_get_attachment_image( $attachment_id, $image_size );?></td><?php}

希望这会有用.

I'm trying to include a product thumbail alongside the name and price of grouped products. Currently, one parent product includes 20 or so child (grouped) products, and as default the page only displays the quantity chooser, product name, price and add to cart button at the bottom of the list. All of the products are listed in a big table one under the other, and I want to include an individual product image for each seperate product.

Currently, by editing the /single-product/add-to-cart/grouped.php product file, i've managed to get it to display a small image but only of the main parent product by adding the following in a DIV after the product title php:

<div class="images">

<?php if ( has_post_thumbnail( $post_id ) ) { ?>

<a itemprop="image" href="<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post_id ) ); ?>" class="zoom" rel="thumbnails" title="<?php echo get_the_title( get_post_thumbnail_id( $post_id ) ); ?>"><?php echo get_the_post_thumbnail( $post_id, apply_filters( 'grouped_product_large_thumbnail_size', 'shop_thumbnail' ), array( 
'title' => get_the_title( get_post_thumbnail_id( $post_id ) ), 
) ); ?></a>

<?php } ?>

</div>

I know this code is only copied from the bundled product image, but it's the closest i've got. You can see the example of what I mean here:

http://hallmark.digitalstorm.co.uk/product/luxor-custom-built-arrangement/

Any help would be really appreciated, as i know i must be really close.

解决方案

Here is the code you are looking for:

add_action( 'woocommerce_grouped_product_list_before_price', 'woocommerce_grouped_product_thumbnail' );

function woocommerce_grouped_product_thumbnail( $product ) {
    $image_size = array( 20, 20 );  // array( width, height ) image size in pixel 
    $attachment_id = get_post_meta( $product->id, '_thumbnail_id', true );
    ?>
    <td class="label">
        <?php echo wp_get_attachment_image( $attachment_id, $image_size ); ?>
    </td>
    <?php
}

Hope this will be useful.

这篇关于Woocommerce 分组产品图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆