Variations table

WCPT PRO provides you the facility to create a variations based table. Please note:

  • This table will show product variations in separate rows
  • The table will only show product variations, it will not show other product types such as variable and simple
  • It is useful when you need to display the variations of a single variable product in a table

Using the variations table you can make it much simpler for the customer to find and purchase the product variation that they need. It offers a far better user experience than the default WooCommerce attribute dropdowns which can be confusing when some variations are not available.

Variation tables can be of any size, they can contains 100s of products if required and support filtering and pagination as well.

To create a product variations table simply create a product table using the product table editor and in the shortcode add the product_variations=”true” attribute and ids= “111” where 111 is ID of the variable product.

[product_table id="123" ids="111" product_variations="true"]

In the above example replace id value with table ID and ids value with the variable product’s ID. 

Show variations on the product page

You can place the shortcode in the description or short description of a product to make the table appear on its product page. In this case you do not need to enter the ‘ids’ shortcode attribute as the shortcode will automatically use the current product id if ids is left empty. 

So, writing :

[product_table id="123" product_variations="true"] 

will be enough in the product description. You do not need to enter ids=”111″ as the plugin will automatically add it.

If you do not want to type in the shortcode on every variable product page, but you need the variations table to show up on all those pages, you can add the shortcode via PHP. This is not part of the plugin facilities however and can be achieved via a custom work request. 

Add variation product table to product pages via PHP

Add the following to your child theme’s functions.php file to add variation table in the product description (in the shortcode replace id=”122″ with your table id):

// wcpt custom: adds variation table in product main description
add_filter('the_content', 'wcpt__custom__variation_table__in_content');
function wcpt__custom__variation_table__in_content( $content ){
  global $product;

  if( 
    ! empty( $product ) &&
    function_exists('is_product') &&
    is_product() &&
    $product->get_type() === 'variable'
  ){
    $content = '[product_table id="122"]' . $content;
  }

  return $content;
}

To add variation table before the product variation form on product pages, use this (in the shortcode replace id=”122″ with your table id):


// wcpt custom: adds variation table above product form
add_action('woocommerce_before_variations_form', 'wcpt__custom__variation_table__before_form' );
function wcpt__custom__variation_table__before_form(){
  global $product;

  if( 
    ! empty( $product ) &&
    function_exists('is_product') &&
    is_product() &&
    $product->get_type() === 'variable'
  ){
    echo do_shortcode( '[product_table id="122"]' );
  }
}