Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Yorlinq/27c4528636ce4273c2de7910238ee596 to your computer and use it in GitHub Desktop.

Select an option

Save Yorlinq/27c4528636ce4273c2de7910238ee596 to your computer and use it in GitHub Desktop.
Shortcode for 'Product price' by 'Product id' - WooCommerce
// Shortcode for 'Product price' by 'Product id': [yl_product_price id='']
function yl_product_price_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'] );
$output = $_product->get_price_html();
}
return $output;
}
add_shortcode( 'yl_product_price', 'yl_product_price_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment