Created
January 21, 2026 13:41
-
-
Save plugin-republic/b7d8d8bf04262b5fb31d3fb469c1b50a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment