2017-04-20 44 views
0

如何將多個圖像分配到WooCommerce的產品?將多個圖像添加到WooCommerce產品

我想:

update_post_meta($post_id, '_product_image_gallery', $image_id); 

但只分配一個圖像。如果我做一個陣列,它不起作用:

update_post_meta($post_id, '_product_image_gallery', array($image_id,$image_id2)); 

我搜索,但我沒有找到如何分配多個圖像。

回答

0

嘗試這樣的:

update_post_meta($post_id, '_product_image_gallery', $image_id.",". $image_id2); 

實例來完成:

$images_ids = array(); 
$images_meta = ""; 
    foreach ($images_ids as $im_id) { 
     if (is_null(get_post_meta($post_id,"_product_image_gallery"))) 
     add_post_meta($post_id,"_product_image_gallery",$im_id); 
     else { 
     $images_meta = get_post_meta($post_id,"_product_image_gallery",true);    
     update_post_meta($post_id,"_product_image_gallery",$images_meta.",".$im_id); 
    } 
相關問題