Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Yorlinq/bb8440b3d0f8372df66315195ac0f8c6 to your computer and use it in GitHub Desktop.
Save Yorlinq/bb8440b3d0f8372df66315195ac0f8c6 to your computer and use it in GitHub Desktop.
Shortcode for 'Product image url' by 'Product id' - WooCommerce
// Shortcode for 'Product image url' by 'Product id': [yl_product_image_url] id=''
function yl_product_image_url_shortcode($atts) {
$atts = shortcode_atts( array(
'id' => null,
), $atts );
if (intval( $atts['id'] ) > 0 && function_exists('wc_get_product')) {
$_product = wc_get_product($atts['id']);
$image_id = $_product->get_image_id();
$output = wp_get_attachment_image_url($image_id, 'full');
}
return $output;
}
add_shortcode( 'yl_product_image_url', 'yl_product_image_url_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment