Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Yorlinq/d3ceb68acc7bd2cd881b0b1e60ffc700 to your computer and use it in GitHub Desktop.
Save Yorlinq/d3ceb68acc7bd2cd881b0b1e60ffc700 to your computer and use it in GitHub Desktop.
Shortcode for 'Product description' by 'Product id' - WooCommerce
// Shortcode for 'Product description' by 'Product id': [yl_product_short_desciption id='']
function yl_product_short_desciption_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->post->post_excerpt;
}
return $output;
}
add_shortcode( 'yl_product_short_desciption', 'yl_product_short_desciption_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment