php - woocommerce thumbnail not working on cart page
one text
I have several thousand products on the store that do not have a thumbnail. So I came up with a code to get them from the "featured-images" attribute, which has a link in it. On the store page, the category page works fine, but the product in the cart does not display the image. What am I doing wrong?
function alterImageSRC($image, $attachment_id, $size, $icon){
global $product;
$url = "https://website.com/wp-content/uploads/thumbs/placeholder.png";
if (!is_null($product)) {
$optimex_featured = $product->get_attribute( 'pa_featured-images' );
$url = "https://website.com/wp-content/uploads/thumbs/$optimex_featured";
}
$image[0] = $url;
return $image;
}
add_filter('wp_get_attachment_image_src', 'alterImageSRC', 10, 4);
Source