How to add images to the Woocommerce Gallery

Est. Reading: 1 minute
By: kingtut
Created: 07/31/2017
Category:
Difficulty: Beginner

How to add images to the Woocommerce Gallery

×Warning: This tutorial was created 2673 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

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, ',') );
  }

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right