// Get WooCommerce product name by ID via shortcode: [iw_product_name id='']
function iw_product_name_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_title();
}
return $html;
}
add_shortcode( 'iw_product_name', 'iw_product_name_shortcode' );
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter