Ask SkyVerge: Change the WooCommerce Additional Information Tab September 04 2014

Today’s Ask SkyVerge question comes from Liz:

How can I remove the weight from the WooCommerce Additional Information tab? I want to keep my attributes in the tab, but not the weight. It would also be really cool if my attributes could be a list instead of comma separated. Is this possible?

Thanks so much for the great help on your blog!


These require a couple of minor adjustments to your site and should be pretty easy to do. First, remember to check out our tutorial on How to Add Custom Code to your site so that we’re doing this correctly.

Since these are changes that we want to keep around no matter which theme we use, we don’t want to add them to our theme’s functions.php file. Instead, we’ll add them using a custom plugin or within the Code Snippets plugin. Let’s tackle the first part of the question to remove the weight info.

When you add shipping information to your product (weight and dimensions) these are automatically added to the WooCommerce Additional Information tab on the product page. You could always remove this tab using our WooCommerce Tab Manager, but it’s handy to list out attributes so you may want to keep it around.

The template for the “Additional Information” tab is what adds a list of all of the product attributes. If we dig a bit deeper, we find that these attributes are actually added from the product-attributes.php template via this function: enable_dimensions_display(). There’s a filter available that will let us change the dimensions display. We can set this to ‘false’ by adding this new code snippet:

add_filter( 'wc_product_enable_dimensions_display', '__return_false' );

Please note that this will remove both the weight AND the product dimensions (all shipping information) from the WooCommerce Additional Information tab. Unfortunately, these are both added using the same check, and to remove only the weight we’d have to override the product-attributes.php template (which you should really avoid doing for future upgrades).

Now weight and dimensions will be removed from this tab, and the tab will be hidden unless some attributes have been checked as “Visible on the Product Page”. This will re-add the tab and list your attributes!

Now let’s tackle question #2. If we go back to the product-attributes.php template, we discover a handy filter in this file to change the output of the attributes. Instead of creating a comma-separated list of product attributes, let’s put a line break after each attribute. We actually use this snippet ourselves to display the attributes for our WooCommerce iPhone App.

We’ll make a function that returns almost the same exact thing, but we’ll replace the commas with a <br /> to create a line break. Create a new code snippet, then insert this code:

function skyverge_change_attribute_list_display( $output, $attributes, $values ) {

	return wpautop( wptexturize( implode( '<br />', $values ) ) );
}
add_filter( 'woocommerce_attribute', 'skyverge_change_attribute_list_display', 10, 3 );

Want to use something else to separate these characters? You could change the <br /> to a pipe character: | or something else instead.

We’d love to hear about it if you use either of these tips! Let us know in the comments :) .

The post Ask SkyVerge: Change the WooCommerce Additional Information Tab appeared first on SkyVerge.