How to add a Warranty tab to WooCommerce products
Shoppers buying anything that can break look for the warranty before they pay. A Warranty tab next to Description answers that without cluttering the product description. 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 Any store pack, and edit the Warranty tab.
Option 1: A code snippet
This adds a Warranty tab to every product. If a product has a custom field named warranty, that text is shown; otherwise the default text is used. We tested it on WooCommerce with both a block theme and a classic theme.
add_filter( 'woocommerce_product_tabs', function ( $tabs ) {
$tabs['warranty'] = array(
'title' => 'Warranty',
'priority' => 25,
'callback' => function () {
global $product;
// Use this product's own "warranty" custom field if it has one.
$text = get_post_meta( $product->get_id(), 'warranty', true );
if ( ! $text ) {
$text = 'Every product is covered by a 1-year warranty against defects. Email us your order number to make a claim.';
}
echo '<h2>Warranty</h2>';
echo wpautop( esc_html( $text ) );
},
);
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 warranty. To fill it in, open a product, click Screen Options at the top right, tick Custom Fields, then add a field with the name warranty 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 Any store or Electronics & gadgets.
- Click Edit next to Warranty, replace the text in [brackets] with your own, and save.
- Open a product, go to Product data → Product tabs, choose Warranty, 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