Support

Account

Home Forums General Issues using same field for different purpose

Solving

using same field for different purpose

  • I’ve this code below copying acf gallery to woocommerce _product_image_gallery. runs perfectly.
    but when I choose field type as “Justified Image Grid” it shops working. how can I solve this problem ???

    any idea ?

    function use_acf_fields_for_product_photos($post_id) {
    if(‘product’ != get_post_type($post_id)) {
    return false;
    }

    $product_gallery = get_field(‘proimages’, $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);

  • but when I choose field type as “Justified Image Grid” it shops working.

    There is no such selection for a gallery field in ACF.

  • I suspect you are using a third party addon called “Justified Image Grid”?

    What your current code does is replace the image IDs that woocommerce uses to generate the gallery with IDs provided by an ACF field.

    The “Justified Image Grid” field is a field that outputs different content. Even if you managed to get WooCommerce to use the images selected in that field you wouldn’t get the grid that I assume you’re after.

    What you could try however:

    //Remove the default product gallery entirely
    remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
    
    //Output the justified image grid instead
    add_action( 'woocommerce_before_single_product_summary', 'my_justified_image_grid', 20 );
    function my_justified_image_grid() {
        the_field('proimages');
    }

    I don’t know if this will work out-of-the-box.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.