Skip Navigation

[Resolved] Adding to Woocommerce Gallery with CRED form

This thread is resolved. Here is a description of the problem and solution.

Problem:

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.

Solution:

There isn't such kind of built-in feature within Toolset Forms plugin, see our document:

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.

Relevant Documentation:

https://toolset.com/documentation/user-guides/front-end-forms/creating-woocommerce-products-using-cred-forms/#which-product-fields-you-can-use-in-toolset-forms

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by mandyM-2 4 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1658371

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

#1659619

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

#1659653

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

#1659659

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

#1659737

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];
#1662899

Have contacted WP Offload Media thanks