1. Home
  2. Knowledge Base
  3. Text Preview for Add-Ons Ultimate
  4. Advanced Topics for Text Preview
  5. How to use different archive images from product featured images
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. How To Guides
  5. How to use different archive images from product featured images

How to use different archive images from product featured images

If you are using Product Add-Ons Ultimate and the Image Preview or Text Preview extensions, you might want to display a different product image on the shop page from the default featured image on the product page itself.

For example, the featured image for the Custom T-Shirt Designer in the screenshots below in different in the shop page and the product page. This is what the user sees in the shop page:

Archive page

And this is what they see when the access the product page:

Featured image

To use a different image for your shop page:

  • Upload your alternate image to your media library. Copy the image URL when it has uploaded
  • Enter your product screen. In the ‘Custom Fields’ section, add a new custom field
  • Define the custom field name as pr_custom_archive_image and paste the image URL in the value field
Custom field archive image url x.jpg
  • Finally, add this snippet
<?php
/**
* If a product has an alternative featured image, display that on the archive page
*/
function pr_demo_product_get_image( $image, $product, $size, $attr, $placeholder ) {
if( is_product() ) {
// We're on a product page so just return the image
return $image;
}
$product_id = $product->get_id();
// Check if there's a custom image for the archive
$image_url = get_post_meta( $product_id, 'pr_custom_archive_image', true );
if( $image_url ) {
$attachment_id = attachment_url_to_postid( $image_url );
$image = wp_get_attachment_image( $attachment_id, 'woocommerce_thumbnail' );
}
return $image;
}
add_filter( 'woocommerce_product_get_image', 'pr_demo_product_get_image', 10, 5 );

Here’s how to add a snippet.

Was this article helpful?

Related Articles