How to add images to the Woocommerce Gallery

Labels

This Discussion is public

Notifications

The process is simple. Create a file/image upload field that allows multiple images, get the field ID and form ID, add this to your theme functions and modify the field ID and form ID in the code to match yours.

// Adds images to Woocommerce Gallery

add_action('frm_after_create_entry', 'add_gallery_images', 42, 2);
function add_gallery_images($entry_id, $form_id){
if ( $form_id == 9 ) { // change to match your form ID
global $frm_entry;
$entry = $frm_entry->getOne($entry_id);
$post_id = $entry->post_id;
$images = $_POST['item_meta'][104]; // change 104 to the field ID of your image upload field
$image = implode($images,',');
update_post_meta( $post_id, '_product_image_gallery', ltrim( $image, ',') );
}

Thanks for posting the tip, kingtut!

Reply to this Discussion