0 Voter

[WooCommerce] Missing thumbnails

Can we address the problem with missing thumbnails on thank you/order details pages, admin order view and emails? I managed to do this myself but not without modifying core files slightly and would love to see it implemented so I don't have to fix it manually on every update.


We can easly save all our lumise data in product meta on checkout.


add_action( 'woocommerce_checkout_create_order_line_item', 'lumise_order_item_data', 20, 4 );

function lumise_order_item_data( $item, $cart_item_key, $values, $order ) {

    if (isset($values['lumise_data'])) {

        $item->update_meta_data( '_lumise_data', $values['lumise_data'] );

    }

}


Retrieve it and replace our thumbnail using woocommerce_order_item_thumbnail filter. It's working, sort of, for 1-2 seconds but then our thumbnail url gets moved from /uploads/lumise_data/user_data to uploads/lumise_data/orders (with isn't a problem to fix) but also renamed based on randomized string (generate_id) with I have a problem to retrieve (had to change core file to comment that part). We don't even need randomized name, maybe "order_id '-' current name" to be sure that it's unique and easier to retrieve.


add_filter('woocommerce_order_item_thumbnail', 'lumise_order_item_thumbnail', 10, 2);

function lumise_order_item_thumbnail($product_image, $item){

    global $lumise, $lumise_cart_thumbnails;

    $item_data = $item->get_data();

    $item_id = $item_data['id'];

    $lumise_data =  wc_get_order_item_meta( $item_id, '_lumise_data', true );

    $design_thumb = '';

    if (isset($lumise_data)) {

        $cart_item_data = $lumise->lib->get_cart_data( $lumise_data );

        $color = $lumise->lib->get_color($cart_item_data['attributes']);

        if( isset($cart_item_data['screenshots']) && is_array($cart_item_data['screenshots']) ){

            $uniq = uniqid();

            $lumise_cart_thumbnails[$uniq] = array();

            foreach ($cart_item_data['screenshots'] as $screenshot) {

                $screenshot = str_replace('user_data', 'orders', $screenshot);

                $design_thumb .= '<img style="background:'.$color.';padding: 0px;" class="lumise-cart-thumbnail" src="'.$lumise->cfg->upload_url.$screenshot.'" />';

            }

        }

    }

    if (intval($lumise->cfg->settings['show_only_design']) == 1 && isset($item['lumise_data']) ) {

        $product_image = '';

    }

    return $product_image.$design_thumb;

}


With very similar code we can also fix thumbnails on admin order details using woocommerce_admin_order_item_thumbnail filter.