How to add an Ingredients tab to WooCommerce products
Food, drink, supplement and beauty shoppers check ingredients and allergens before they buy. An Ingredients tab keeps that information easy to find and separate from your sales copy. WooCommerce doesn't include one, so here are two ways to add it: a short code snippet, or the free ShelfTabs plugin with no code.
Short version: Developers can paste the snippet below. Everyone else can install free ShelfTabs, add the Food, drink & supplements pack, and edit the Ingredients tab.
Option 1: A code snippet
This adds an Ingredients tab only to products in your Food category; change food to your category's slug. Each product's text comes from a custom field named ingredients. We tested it on WooCommerce with both a block theme and a classic theme.
add_filter( 'woocommerce_product_tabs', function ( $tabs ) {
global $product;
// Only on products in the "Food" category (use your category's slug).
if ( ! has_term( 'food', 'product_cat', $product->get_id() ) ) {
return $tabs;
}
$tabs['ingredients'] = array(
'title' => 'Ingredients',
'priority' => 25,
'callback' => function () {
global $product;
$text = get_post_meta( $product->get_id(), 'ingredients', true );
echo '<h2>Ingredients</h2>';
echo wpautop( esc_html( $text ? $text : 'Ingredients are listed on the package.' ) );
},
);
return $tabs;
} );
Where to put it: In the free Code Snippets plugin, or in your child theme's functions.php. Don't edit your main theme's files, because a theme update would erase your change.
Give each product its own text
The snippet reads a custom field named ingredients. To fill it in, open a product, click Screen Options at the top right, tick Custom Fields, then add a field with the name ingredients and your text as the value. Update the product.
Option 2: No code, with ShelfTabs (free)
- Download shelftabs.zip (don't unzip it). In WordPress, go to Plugins → Add New → Upload Plugin, choose the file, click Install Now, then Activate.
- Go to WooCommerce → ShelfTabs. Under Start from a ready-made pack, click Add this pack on Food, drink & supplements or Beauty & personal care.
- Click Edit next to Ingredients, replace the text in [brackets] with your own, and save.
- Open a product, go to Product data → Product tabs, choose Ingredients, and update the product.
With ShelfTabs Pro, one rule shows the tab on every product in a category automatically, and merge tags fill in each product's own details, such as its SKU, weight or dimensions.
Skip the code
ShelfTabs is free and includes ready-made tabs for 10 kinds of store. ShelfTabs Pro adds automatic tabs by category, from $29 a year with a 30-day refund if it doesn't work.
Download free ShelfTabs See ShelfTabs