Hello,
I followed the solution form this topic (https://toolset.com/forums/topic/cred-repeating-image-fields-gallery-woo-and-non-woo/) to set woo gallery but it doesn't work for me.
First, I removed wpcf- prefix from the code.
If I add it in front of the field slug, the pictures don't even show in the gallery custom field in back-end editor (they are uploaded into the media library, though) and neither in woocomerce gallery.
Without the prefix the pictures show in the back-end in my gallery custom fields but not in woocommerce gallery.
I only changed form id and my custom field slug in the provided code..
What am I missing? Please, help.
Hi,
Thank you for contacting us and I'd be happy to assist.
To troubleshoot why the same code snippet is not working on your website, I'll need its clone/snapshot.
Can you please share it, as explained in this guide?
https://toolset.com/faq/provide-supporters-copy-site/
Note: I've set your next reply as private.
regards,
Waqar
Hello, is there any progress?
Thanks.
Hi,
Thank you for waiting, while I performed some troubleshooting.
I noticed that in your target form "Alternative places form" (ID: 39), the option "Use the WordPress Media Library manager for image, video, audio, or file fields" was not checked.
( screenshot: versteckter Link )
For the code snippet from Christian to work ( ref: https://toolset.com/forums/topic/cred-repeating-image-fields-gallery-woo-and-non-woo/#post-553621 ), the media library option needs to be checked.
Here is the slightly updated code snippet, which will work whether that option is turned on or not:
add_action('cred_save_data', 'cred_product_gallery_action',10,2);
function cred_product_gallery_action($post_id, $form_data)
{
global $wpdb;
// if a specific form
if ($form_data['id']==39)
{
if (isset($_POST['wpcf-photo-gallery-alt']))
{
$list_ids = array();
$existing_values = get_post_meta( $post_id, 'wpcf-photo-gallery-alt', false );
foreach($existing_values as $url)
{
$item_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ));
$list_ids[] = $item_id[0];
}
update_post_meta($post_id, '_product_image_gallery', implode($list_ids,','));
delete_post_meta($post_id, 'wpcf-photo-gallery-alt');
}
}
}
I hope this helps and please let me know how it goes.
regards,
Waqar
Thank you so much, it works great now.
I had to disable media library button because I got some other issues with the featured image but I'll create a new ticket if I can't sort it out by myself.
Thanks again and all the best,
pz