• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2893

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Checkout

Get & Display Variation Description on Single Products

Category: WooCommerce
  • Description

You can display the product variation description anywhere on your single product page using PHP code with javascript or pure PHP code.

Using PHP code if you have the variation id like this :

add_action( 'woocommerce_before_single_product_summary', 'variable_product_description_by_id' );
function variable_product_description_by_id() {

global $product;

$variation = wc_get_product( '14803' );

if ( ! $product->is_type( 'variable' ) AND ! $variation ) 
return;

echo $variation->get_description();

}

Or using Javascript on variation selection like this :

Get All Variation Descriptions

You can also use the code from the download folder to get all product variation descriptions using data from the $variation and $variation_ids.

add_action( 'woocommerce_before_single_product_summary', 'get_variable_product_descriptions_by_id' );
function get_variable_product_descriptions_by_id() {

global $product;

$variation_ids = $product->get_children();

if ( empty( $variation_ids ) ) {
return;
}

foreach ( $variation_ids as $variation_id ):

$variation   = wc_get_product( $variation_id );

$description = $variation->get_description();

echo $description;

endforeach;

}

Primary Sidebar

Guaranteed code

Written by Brad Dalton specialist for WooCommerce. Read More…

Advertise · WPEngine · Genesis · Log in

  • Code Snippets
  • Tutorials
  • Videos
  • Tags
  • Account
  • Checkout
  • Cart
  • Hire Me