【问题标题】:Woocommerce hook to show product gallery images as full size imagesWoocommerce 钩子将产品图库图像显示为全尺寸图像
【发布时间】:2022-07-04 20:09:15
【问题描述】:

有人可以展示我们如何在 Woocommerce 中使用此代码吗?

我正在使用此代码 Woocommerce product gallery images are showing as full size images instead of thumbnail 但不工作。 (也许,我就是不知道怎么用)

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

     if (is_product()) {

         global $product;

         $attachment_ids = $product->get_gallery_image_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>';

     }

  }

【问题讨论】:

  • 这个钩子用于在循环中显示产品内容。它不清楚你想要达到什么目标。在示例中,用户询问如何在缩略图中制作全尺寸图像。您在问如何使这些图像全尺寸?这是一个可以帮助您的视觉指南 - businessbloomer.com/…

标签: php wordpress woocommerce hook-woocommerce


【解决方案1】:

使用

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

而不是

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

【讨论】:

    猜你喜欢
    • 2019-07-07
    • 2017-02-01
    • 2016-05-16
    • 2014-11-19
    • 1970-01-01
    • 2020-01-26
    • 2015-01-04
    • 1970-01-01
    • 2018-01-23
    相关资源
    最近更新 更多