Skip to content

Instantly share code, notes, and snippets.

@iWebbers
Last active August 11, 2018 02:04
Show Gist options
  • Save iWebbers/343b27448aeff31f47d64f0f85e2c628 to your computer and use it in GitHub Desktop.
Save iWebbers/343b27448aeff31f47d64f0f85e2c628 to your computer and use it in GitHub Desktop.
// Get WooCommerce product image by ID via shortcode: [iw_product_image id='']
function iw_product_image_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => null,
), $atts, 'bartag' );
$html = '';
if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
$_product = wc_get_product( $atts['id'] );
$html = $_product->get_image();
}
return $html;
}
add_shortcode( 'iw_product_image', 'iw_product_image_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment