💡
Woocommerce
View WebsiteFlatsomeWoo
  • Get Started
  • Features
    • Reinstall Woocommerce Missing Pages
  • Customization
    • Hide/Customize Woocommerce Components with CSS
    • Remove Additional Information Tab @ Single Product
  • Shortcode
    • Long Description Shortcode for Woocommerce
    • PHP Snippet: Woocommerce Reviews as Shortcode
Powered by GitBook
On this page
  1. Shortcode

Long Description Shortcode for Woocommerce

PreviousRemove Additional Information Tab @ Single ProductNextPHP Snippet: Woocommerce Reviews as Shortcode

Last updated 10 months ago

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:

  1. Log into your WordPress dashboard and navigate to the ‘Appearance’ section.

  2. Click on the ‘Editor’ option.

  3. In the right-hand pane, select the ‘functions.php’ file.

  4. Copy and paste the code snippet provided above into the file.

  5. Click on the ‘Update File’ button to save your changes.

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.

That’s it! You’ve now successfully added the code snippet to your WooCommerce site.

What you see in UX Builder