简体   繁体   中英

Url instead of Woocommerce thumbnail

I have several thousand photos to add as "thumbnail". The products are already added to WooCommerce, but without the "thumnail". What do I have:

  • links to photos that are related to the SKU
  • each product has a special "photo" attribute that displays a link to the photo. How do I transfer all this to a thumbnail automatically?

I want to change the default "thumbnail" to download from url. It works on FRONT, but I get an error in the admin when I go to the products tab "Call the get_attribute () member function on null"

function alterImageSRC($image, $attachment_id, $size, $icon){      
    
    global $product;
    $koostis = $product->get_attribute( 'pa_featured-images' );  
   
    $image[0] = "https://link.com/wp-content/uploads/thumbs/'$koostis'";

    return $image;
}
add_filter('wp_get_attachment_image_src', 'alterImageSRC', 10, 4);

I did it. I'm attaching a working code that generates a thumbnail based on an attribute. There is a link to the picture in the atrubucie of this product.

function alterImageSRC($image, $attachment_id, $size, $icon){      
    $product = wc_get_product();
    $optimex_featured = $product->get_attribute( 'pa_featured-images' );
    $image[0] = "https://link.com/wp-content/uploads/thumbs/'$optimex_featured'";
    return $image;
}
add_filter('wp_get_attachment_image_src', 'alterImageSRC', 10, 4);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM