Skip to content

Instantly share code, notes, and snippets.

@generatepress
Last active April 29, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save generatepress/57610006a85c206fea53131986022a91 to your computer and use it in GitHub Desktop.
Save generatepress/57610006a85c206fea53131986022a91 to your computer and use it in GitHub Desktop.
Try new WC secondary image function
function generatepress_wc_secondary_product_image() {
$post_type = get_post_type( get_the_ID() );
if ( 'product' == $post_type && method_exists( 'WC_Product', 'get_gallery_image_ids' ) ) {
$product = new WC_Product( get_the_ID() );
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids && generatepress_wc_get_setting( 'product_secondary_image' ) && generatepress_wc_get_setting( 'product_archive_image' ) && has_post_thumbnail() ) {
$secondary_image_id = $attachment_ids['0'];
echo wp_get_attachment_image( $secondary_image_id, 'shop_catalog', '', $attr = array( 'class' => 'secondary-image attachment-shop-catalog' ) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment