Skip to content

Add WooCommerce Product Price as a Shortcode

Add WooCommerce Price as a shortcode using the product ID for the correct product

add_shortcode( 'cl_product_price', 'cl_woo_product_price_shortcode' );
/**
 * Shortcode WooCommerce Product Price.
 *
 */
function cl_woo_product_price_shortcode( $atts ) {
	
	$atts = shortcode_atts( array(
		'id' => null
	), $atts, 'cl_product_price' );
 
	if ( empty( $atts[ 'id' ] ) ) {
		return '';
	}
 
	$product = wc_get_product( $atts['id'] );
 
	if ( ! $product ) {
		return '';
	}
 
	return $product->get_price_html();
}

And use the shortcode with the Product ID number.

[cl_product_price id="1011"]

Leave a Comment





Scroll To Top