Get Product List by product ids woocommerce như thế nào?

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

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,030
    Đã được thích:
    81
    Điểm thành tích:
    48
    HI mọi người, mình đang muốn lấy danh sách sản phẩm khi được truyền vào từ 1 danh sách id của acf plugin về.
    Get Product List by product ids woocommerce? hiện tại mình lấy dữ liệu từ acf database về dữ liệu danh sách ids của sản phẩm, giờ mình muốn lấy danh sách sp đó ra thì làm như thế nào?
    $groupproduct = get_field( 'id_product_list', 'homepage' );
     
    Cảm ơn đã xem bài:

    Get Product List by product ids woocommerce như thế nào?

  2. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,907
    Đã được thích:
    1,199
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Bạn làm như sau nhé:
    PHP:
    ////get san pham
      
    $groupproduct get_field'id_product'$idpage );
      if(! empty(
    $groupproduct))
      {
        
    $arrayproductg explode(','$groupproduct);
        
    $args = array(
          
    'post_type' => 'product',
          
    'include' => $arrayproductg//'meta_value' => array('yes'),
        
    );
     
        
    $products wc_get_products$args );
     
        foreach ( 
    $products as $pro ) {
          
    //////////////////////////////
          
    $contents .= '<div class="cs-itemslider item-product">';
              
    $contents .= '<div class="cs-imgthumb">'.get_the_post_thumbnail($pro->get_id(), 'thumnail', array( 'class' =>'thumnail') ).'</div>';
              
    $contents .= '<div class="cs-iteminfo"><p class="csld-titlepro">'.$pro->get_title().'</p>';
              
    $contents .= '<p class="csld-despro">'.get_the_excerpt$pro->get_id() ).'</p>';
              
    $contents .= '<div class="price-product"><span>Price: </span>'.$pro->get_price_html().'</div>';
              
    $contents .= '<a class="cs-readmore" href="'.get_permalink$pro->get_id()).'">Readmore ></a>';
          
    $contents .= '</div></div>';
          
    ///////////////////////////////
        
    }
     
      }
    • Với giá trị của ACF truyền vào dạng danh sách: 110,220,112 (cách nhau dấu phẩu)
    Hoặc code sau:
    PHP:
    $ids '123,431,321,554';
    $ids explode','$ids );
    $ids array_map'trim'$ids );
    $args = array(
        
    'post__in' => $ids,
        
    'post_type' => 'product',
        
    'numberposts' => -1,
        
    'posts_per_page' => -1,
        
    'orderby' => 'post__in',
        
    'ignore_sticky_posts' => true,
    );
    $products = new WP_Query$args );
    }
    if ( 
    $products->have_posts() ) :
     while ( 
    $products->have_posts() ) : $products->the_post();
        global 
    $product;
        
    $price $product->get_price();
        
    $proid $product->get_id();
        .... 
    lấy dữ liệu
     
    endwhile; // end of the loop.
    endif;
    wp_reset_query();
     
    Chỉnh sửa cuối: 13/6/22
    seolagi thích bài này.
  3. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,030
    Đã được thích:
    81
    Điểm thành tích:
    48
    Dạ cảm ơn ad, em áp dụng ngay ạ
     
  4. Quyenj
    Tham gia ngày:
    11/5/22
    Bài viết:
    2
    Đã được thích:
    0
    Điểm thành tích:
    1
    Giới tính:
    Nam
    Lắp đặt camera tại nhà uy tín nếu bạn quan tâm hãy liên hệ...
     


Chủ để tương tự : Product List
Diễn đàn Tiêu đề Date
Mã nguồn mở Wordpress Get list Gallery images url from product in woocommerce 28/10/21
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 Get product tags name by product id woocommerce wordpress? 13/6/23