Get list Gallery images url from product in woocommerce

Thảo luận trong 'Mã nguồn mở Wordpress' bắt đầu bởi seolagi, 28/10/21.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,027
    Đã được thích:
    80
    Điểm thành tích:
    48
    Get list Gallery images url from product in woocommerce, lấy danh sách hình ảnh sản phẩm trong woocommerce gồm: url hình ảnh, full hình ảnh mọi thứ về hình ảnh slider show của sản phẩm.

    Lấy toàn bộ hình ảnh trong Gallery của 1 sản phẩm như sau:
    PHP:
    <?php
    global $product;
    $attachment_ids $product->get_gallery_attachment_ids();
    foreach( 
    $attachment_ids as $attachment_id )
    {
      
    //Get URL of Gallery Images - default wordpress image sizes
      
    echo $Original_image_url wp_get_attachment_url$attachment_id );
      echo 
    $full_url wp_get_attachment_image_src$attachment_id'full' )[0];
      echo 
    $medium_url wp_get_attachment_image_src$attachment_id'medium' )[0];
      echo 
    $thumbnail_url wp_get_attachment_image_src$attachment_id'thumbnail' )[0];

      
    //Get URL of Gallery Images - WooCommerce specific image sizes
      
    echo $shop_thumbnail_image_url wp_get_attachment_image_src$attachment_id'shop_thumbnail' )[0];
      echo 
    $shop_catalog_image_url wp_get_attachment_image_src$attachment_id'shop_catalog' )[0];
      echo 
    $shop_single_image_url wp_get_attachment_image_src$attachment_id'shop_single' )[0];

      
    //echo Image instead of URL
      
    echo wp_get_attachment_image($attachment_id'full');
      echo 
    wp_get_attachment_image($attachment_id'medium');
      echo 
    wp_get_attachment_image($attachment_id'thumbnail');
      echo 
    wp_get_attachment_image($attachment_id'shop_thumbnail');
      echo 
    wp_get_attachment_image($attachment_id'shop_catalog');
      echo 
    wp_get_attachment_image($attachment_id'shop_single');
    }
    ?>
    • Các bạn lấy kiểu nào thì áp dụng sử dụng cái đó, code khá ổn đã test qua chạy không bị lỗi
    Lấy ảnh bìa của sản phẩm:
    PHP:
    <?php
    global $product;
    $image_id  $product->get_image_id();
    echo 
    wp_get_attachment_image$image_id'full' );
    ?>
    • Đổi full thành: medium, thumbnail, shop_thumbnail, shop_catalog, shop_single để đổi kích thước hiển thị của hình sản phẩm.
     
    Cảm ơn đã xem bài:

    Get list Gallery images url from product in woocommerce

    Last edited by a moderator: 28/10/21


Chủ để tương tự : list Gallery
Diễn đàn Tiêu đề Date
Mã nguồn mở Wordpress Get Product List by product ids woocommerce như thế nào? 29/3/22
Mã nguồn mở Wordpress Get Prodcut list by category id or list id products woocommerce ? 28/10/21
Mã nguồn mở Wordpress Get list taxonomy term attribute slug and name woocommerce product 20/8/21
Mã nguồn mở Wordpress Lấy danh sách hình ảnh thư viện gallery images products trong woocommerce 19/3/24
Mã nguồn mở Wordpress Change gallery thumbnails count & number default 4 Woocommerce 3/8/23