将产品图像添加到产品列表并存档woocommerce

时间:2019-07-25 09:04:10

标签: php wordpress woocommerce

我希望能够将列表中的每个产品的图像内的可点击缩略图添加到存档和产品类别页面(在列表中显示产品)。

我尝试通过检查功能来获取产品的图片库并遍历它们以显示它们,但是它什么也没显示。我不知道如何正确遍历每个产品,并在图像中显示所有该产品的图库。

add_action('woocommerce_shop_loop_item_title','wps_add_extra_product_thumbs', 5);
function wps_add_extra_product_thumbs() {

    if ( is_shop() || is_archive() ) {

        global $product;

        $attachment_ids = $product->get_gallery_attachment_ids();
var_dump($attachment_ids);
        echo '<div class="product-thumbs">';

        foreach( array_slice( $attachment_ids, 0, 3 ) as $attachment_id ) {

            $thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' )[0];

            echo '<img class="thumb" src="' . $thumbnail_url . '">';

        }

        echo '</div>';

    }

}

(我通常要实现的目标是:当您将鼠标悬停时,显示图库列表,当您单击图像时,它将使用我的图库小部件将其打开。)

what I'm trying to achieve

0 个答案:

没有答案