Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zarankumar/f80a73598152edf7d67a8c91dbf3be25 to your computer and use it in GitHub Desktop.
Save zarankumar/f80a73598152edf7d67a8c91dbf3be25 to your computer and use it in GitHub Desktop.
Add image to product gallery programmatically - woocommerce .Woocommerce manage field ‘_product_image_gallery’ with id of images separatly for comma.
@13tjc
Copy link

13tjc commented Oct 25, 2017

I have a similar set up but only one attachment ID gets placed in the product image gallery.
Heres what I got:

$commaList = "2104,2105,2106,";
update_post_meta( $post_id, '_product_image_gallery', $commaList);

Are you sure this works to add images to the product gallery programmatically?

@m-torin
Copy link

m-torin commented Aug 8, 2018

Works for me:
$media = get_attached_media('image', $pid);
update_post_meta($pid, '_product_image_gallery', implode(',', array_keys($media)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment