product deleted lost references of images
-
Hi, I have my site with woocomerce.
I have the following code in my functions.php file, this allowed me to display images in My Account section, for the orders placed. A customer purchase an item than later I deleted (the whole product), and now the customer has an error message.
//Discplay image in order my account // Display the product thumbnail in order view pages add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 ); function display_product_image_in_order_item( $item_name, $item, $is_visible ) { // Targeting view order pages only if( is_wc_endpoint_url( 'view-order' ) ) { $product = $item->get_product(); // Get the WC_Product object (from order item) $product_image = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object) $item_name = '<div class="item-thumbnail">' . $product_image . '</div>' . $item_name; } return $item_name; } //Discplay products column my account orders add_filter( 'woocommerce_my_account_my_orders_columns', 'filter_woocommerce_my_account_my_orders_columns', 10, 1 ); function filter_woocommerce_my_account_my_orders_columns( $columns ) { $new_column = array( 'order-number' => $columns['order-number']); unset($columns['order-number']); $new_column['order-thumbnails'] = ''; return array_merge($new_column, $columns); } add_action( 'woocommerce_my_account_my_orders_column_order-thumbnails', 'filter_woocommerce_my_account_my_orders_column_order', 10, 1 ); function filter_woocommerce_my_account_my_orders_column_order( $order ) { // Loop through order items foreach( $order->get_items() as $item ) { $product = $item->get_product(); // Get the WC_Product object (from order item) $thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object) if( $product->get_image_id() > 0 ) { echo $thumbnail . ' ' ; } } }
I cant restore the product anymore so I created a new one same SKU, name atrributes and I put the images in the folder /public_html/kidsandladiessv.com/wp-content/uploads/2022/05 as that is the location where the first product was refering to. This helped me to at least see the images in the email I sent to the customer, but in My account the customer is still seeing the error.
Fatal error: Uncaught Error: Call to a member function get_image() on bool in /home2/kidsandl/public_html/kidsandladiessv.com/wp-content/themes/astra-child/functions.php:91 Stack trace: #0 /home2/kidsandl/public_html/kidsandladiessv.com/wp-includes/class-wp-hook.php(307): filter_woocommerce_my_account_my_orders_column_order(Object(Automattic\WooCommerce\Admin\Overrides\Order)) #1 /home2/kidsandl/public_html/kidsandladiessv.com/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array) #2 /home2/kidsandl/public_html/kidsandladiessv.com/wp-includes/plugin.php(476): WP_Hook->do_action(Array) #3 /home2/kidsandl/public_html/kidsandladiessv.com/wp-content/plugins/woocommerce/templates/myaccount/orders.php(45): do_action('woocommerce_my_...', Object(Automattic\WooCommerce\Admin\Overrides\Order)) #4 /home2/kidsandl/public_html/kidsandladiessv.com/wp-content/plugins/woocommerce/includes/wc-core-functions.php(345): include('/home2/kidsandl...') #5 /home2/kidsandl/public_html/kidsandladiessv.com/wp-content/plugins/woocomm in /home2/kidsandl/public_html/kidsandladiessv.com/wp-content/themes/astra-child/functions.php on line 91
I dont have much technical kwnoledge but I am afraid this is not a simple reference issue, any idea if this is something I can fix?
So far only solution I found is to remove the code to add the images, but the issue is with just one customer for the deleted product ??The page I need help with: [log in to see the link]
- The topic ‘product deleted lost references of images’ is closed to new replies.