Hi @prakash_s! Thanks for your hint.
I found other details about using ACF plugin fields instead of default Woocommerce fields for product images. Here is 2 steps which I did and now my gallery slider is running correctly:
1 - Create this Field Groups in ACF Plugin :
2- Add this code to functions.php of your theme:
//Remove the default WooCommerce meta boxes for the Product image and Product gallery
function remove_woocommerce_product_image_meta_boxes() {
remove_meta_box('postimagediv', 'product', 'side');
remove_meta_box('woocommerce-product-images', 'product', 'side');
}
add_action('add_meta_boxes', 'remove_woocommerce_product_image_meta_boxes', 40);
// Custom ACF fields to store product featured photo
function load_existing_product_photo_into_acf_image_field($field) {
global $post;
$field['value'] = get_post_meta($post->ID, '_thumbnail_id', true);
return $field;
}
add_filter('acf/load_field/name=product_photo', 'load_existing_product_photo_into_acf_image_field');
// Custom ACF fields to store product gallery
function load_existing_product_gallery_into_acf_gallery_field($field) {
global $post;
$field['value'] = explode(',', get_post_meta($post->ID, '_product_image_gallery', true));
return $field;
}
add_filter('acf/load_field/name=product_gallery', 'load_existing_product_gallery_into_acf_gallery_field');
// Sync ACF Product Images fields into product metadata
function use_acf_fields_for_product_photos($post_id) {
if('product' != get_post_type($post_id)) {
return false;
}
$product_photo = get_field('product_photo', $post_id);
if($product_photo && !empty($product_photo['ID'])) {
update_post_meta($post_id, '_thumbnail_id', $product_photo['ID']);
}
$product_gallery = get_field('product_gallery', $post_id);
if($product_gallery) {
$product_gallery_ids_string = implode(',', wp_list_pluck($product_gallery, 'ID'));
update_post_meta($post_id, '_product_image_gallery', $product_gallery_ids_string);
}
}
add_action('acf/save_post', 'use_acf_fields_for_product_photos', 20);
Regards
Omid