Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce - Just one thumbnail in product page.
function custom_woocommerce_show_product_thumbnails() {
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
if ( ! empty( $attachment_ids ) ) {
$attachment_id = current( $attachment_ids ); // pega o primeiro
$image_link = wp_get_attachment_url( $attachment_id );
if ( ! $image_link ) {
return;
}
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
$image_title = esc_attr( get_the_title( $attachment_id ) );
echo sprintf( '<a href="%s" title="%s">%s</a>', $image_link, $image_title, $image );
}
}
add_action( 'woocommerce_product_thumbnails', 'custom_woocommerce_show_product_thumbnails', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.