Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1423221

    I’m building a bookshop
    Which will present 1000’s of books

    I have connected WooCommerce with the Book Importer as we use BatchLine for stocking supply:
    BCS BatchLine Book Importer (Its working well)

    The import creates 2 custom fields (relevant to my question) main_image and thumbnail_image both populated with url values.
    The Main image appears correctly within a product page.

    However I am trying to work out how I can update the relevant file for the grid, slider, and list Enfold features. I believe from research Enfold is using the shop thumbnail image? I can’t quite work out the structure and if I could develop the files to pull in the url from a Custom Field – thumbnail_image. I assume this is not a function.php solution but developing some code. Can anyone give me any points on how the code is even structured. It looks like it takes information for the html rendering from the WooCommerce files. Batchline inform me it works fine with the shopfront WooCommerce theme, so if anyone who’s the difference, I would be very grateful.

    Best Regards C

    #1423240

    Hey molinesupport,
    Thanks for your question, I’m not familiar with “BatchLine”, but if this works with the shopfront WooCommerce theme, try going to Enfold Theme Options ▸ Shop Options ▸ Product gallery and choose WooCommerce 3.0 product gallery, I assume that you are currently using the Default enfold product gallery option now.
    On the page that you linked to I see the classes for the products that are showing the placeholder images: member-discount discount-restricted
    are you using a “membership” plugin? If you don’t use any restrictions do the images then show correctly?

    Best regards,
    Mike

    #1423246
    This reply has been marked as private.
    #1423727

    Hi,
    Thank you for your patience and for the link to your site, I see that your product imports do not include a “featured image”.
    When I check your “custom fields” I see your images for main_image & thumbnail_image, but from what I can see on my demo, the featured image is not stored as a “custom field” but as the thumbnail_id and are refured to by the attachment ID, and since these images are not in your media library they won’t have a attachment ID.
    Unfortunately I don’t have a way to test this situation because the standard WordPress import/export file (xml) imports the images into the media library, but your import method doesn’t.
    Does your import tool offer any other fields like the thumbnail_id?

    Best regards,
    Mike

    #1423740
    This reply has been marked as private.
    #1423741
    This reply has been marked as private.
    #1423972

    Hi,
    Thank you for your patience and the link to your site, I was able to show the custom field product images (thumbnail_image) on the shop page with this function in your child theme functions.php:

    
        function custom_thumbnail_display() {
            global $product;
            
            // Get the "thumbnail_image" custom field value
            $thumbnail_image_url = get_post_meta( $product->get_id(), 'thumbnail_image', true );
            
            if ( ! empty( $thumbnail_image_url ) ) {
                // If the custom field has a value, display that image
                echo '<img class="bcs-thumbnail" src="' . esc_url( $thumbnail_image_url ) . '" alt="' . esc_attr( $product->get_name() ) . '">';
            } else {
                // Otherwise, display the default WooCommerce placeholder image (optional, as WooCommerce will handle it)
                echo wc_placeholder_img();
            }
        }
        add_action( 'woocommerce_before_shop_loop_item_title', 'custom_thumbnail_display', 10 );
    

    and then I added this css to remove the duplicate woocommerce-placeholder.png when the custom field product image is shown on the shop page

    
    .woocommerce-shop .product .woocommerce-LoopProduct-link .bcs-thumbnail ~ .thumbnail_container {
    	display: none;
    }
    

    So now the result is:
    Enfold_Support_3783.jpeg
    Since you are using the BCS BatchLine Book Importer plugin, the single custom field product main image is shown (main_image) by the plugin, if someone was not using this plugin the custom field product main image could be shown with this function:

    
    //for the single product main image
    function custom_single_product_image_html( $html, $attachment_id ) {
        global $product;
        
        // Get the "thumbnail_image" custom field value
        $thumbnail_image_url = get_post_meta( $product->get_id(), 'main_image', true );
        
        if ( ! empty( $thumbnail_image_url ) ) {
            // If the custom field has a value, return that image as the main product image
            $html = '<img src="' . esc_url( $thumbnail_image_url ) . '" alt="' . esc_attr( $product->get_name() ) . '">';
        }
        
        return $html;
    }
    add_filter( 'woocommerce_single_product_image_thumbnail_html', 'custom_single_product_image_html', 10, 2 );
    

    perhaps this will be helpful to someone in the future.
    Please check your site and let us know if you find this working as my screenshots above, so we can close this thread :)

    Best regards,
    Mike

    #1424098
    This reply has been marked as private.
    #1424100

    Hi,

    Glad we could be of help! Thank you for the kind words. If you have any further questions, please feel free to open another thread and we will gladly try to help you.

    Thank you for using Enfold.

    Best regards,
    Ismael

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Linking external images within – product grid, product slider or product list’ is closed to new replies.