Hook for single product thumbnail
Question
Is there any hook to change the single product thumbnail? I did search a lot on SO as well as over the internet but no luck.
With ‘thumbnail’ I don’t mean changing the size of the current image but I want to completely change/replace the product image (thumbnail) with a new image based on some scenario.
public function pn_change_product_image_link( $html, $post_id ){
$url = get_post_meta( $post_id );
$alt = get_post_field( 'post_title', $post_id ) . ' ' . __( 'thumbnail', 'txtdomain' );
$attr = array( 'alt' => $alt );
$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, NULL );
$attr = array_map( 'esc_attr', $attr );
$html = sprintf( '<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/WP_Suspension_logo.svg/2000px-WP_Suspension_logo.svg.png"', esc_url($url) );
foreach ( $attr as $name => $value ) {
$html .= " $name=" . '"' . $value . '"';
}
$html .= ' />';
return $html;
}
This is what I’m doing now but it’s throwing an error.
Filter, Hook:
post_thumbnail_html
0
2 years
2020-12-15T15:10:18-05:00
2020-12-15T15:10:18-05:00 0 Answers
16 views
0
Leave an answer