Last active
April 29, 2018 15:47
-
-
Save generatepress/57610006a85c206fea53131986022a91 to your computer and use it in GitHub Desktop.
Try new WC secondary image function
This file contains 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
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