I have set up a custom product repeating image field for products _product_image_gallery (woocommerce gallery meta)
How do i get this field to populate the Woocommerce Image gallery? I have read previous tickets about using the cred_save_data hook, but i cannot get it to work.
Do you plan on adding Woocommerce Image Gallery functionality to Cred forms? I thought this would be essential for users like myself who want to use their default Theme layout for Products.
Thanks
Hello,
There isn't such kind of built-in feature within Toolset Forms plugin, see our document:
https://toolset.com/documentation/user-guides/front-end-forms/creating-woocommerce-products-using-cred-forms/#which-product-fields-you-can-use-in-toolset-forms
Product Gallery needs to be handled using custom PHP coding. If you need a non-code solution, add product images using custom fields defined in Types.
And we don't have a plan to support this "Product Gallery " feature.
See similar thread, there is a custom codes example you can try:
https://toolset.com/forums/topic/multi-image-form-post/page/2/#post-1151131
I created an image gallery (additional_images) and added the following code
add_action('cred_save_data', 'func_add_product_gallery_image',10,2);
function func_add_product_gallery_image($post_id, $form_data)
{
global $wpdb;
// if a specific form
if ($form_data['id']==55)
{
if (isset($_POST['wpcf-additional_images']))
{
$list_ids = array();
foreach($_POST['wpcf-additional_images'] 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-product-gallery-image-cred');
}
}
}
Images appear in the backend under my custom image gallery, but not in the woocommerce image gallery. I checked with the theme author and the theme uses the standard _product_image_gallery
It is a custom codes problem, if you need assistance for it, please provide a test site with the same problem, also point out:
- The post form URL
- The problem page URL, where I can submit the form
- Where I can edit your PHP codes
I need to test it in a live website, thanks
You are using "WP Offload Media Lite" plugin in your website, this plugin will change image attachment URL to their CDN URL, so those PHP codes won't work as expected.
You will need to contact "WP Offload Media Lite" support for:
How to retrieve attachment ID from attachment CDN URL
Then use their PHP function to replace these two lines:
$item_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ));
$list_ids[] = $item_id[0];
Have contacted WP Offload Media thanks