Long Description Shortcode for Woocommerce

Would you like to include a detailed and long description of your product in a custom accordion rather than using the default style of your WordPress theme? So, this article is for you.

Long description

Adding this code to your WooCommerce site is easy and will allow you to create a shortcode to display the product description for any product.

// Create a shortcode for product description of Woocommerce

add_shortcode( 'product_description', 'display_product_description' );
function display_product_description( $atts ){
$atts = shortcode_atts( array(
'id' => get_the_id(),
), $atts, 'product_description' );

global $product;

if ( ! is_a( $product, 'WC_Product') )
$product = wc_get_product($atts['id']);

return wpautop($product->get_description());
}

Here are the steps you should take to add the code:

Once you’ve saved the changes to the functions.php file, you will now be able to use the shortcode [product_description] wherever you need to display the product description. And, you’re also able to enter the product’s ID in the shortcode (e.g. ‘[product_description id=123] ’) to get the exactly Product ID. In case you’re adding it directly to the product page, no need to add the product_id.

What you see in UX Builder

Last updated