Add Extra Tabs on WooCommerce Product Page

Add Extra Tabs on WooCommerce Product Page

You need to add the code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

Use the following snippet to add a custom global product tab.

<?php

/* Add Ingredients tab */
function add_ingredients_product_tab_callback( $tabs ) {

	$tabs['ingredients_tab'] = array(
		'title'    => __( 'Ingredients', 'textdomain' ),
		'callback' => 'ingredients_tab_content_callback',
		'priority' => 50,
	);

	return $tabs;

}
add_filter( 'woocommerce_product_tabs', 'add_ingredients_product_tab_callback' );

/* Ingredients tab content */
function ingredients_tab_content_callback( $slug, $tab ) {
	?>
	<h2><?php echo wp_kses_post( $tab['title'] ); ?></h2>
	<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<?php
}

If you have custom field provided in your admin dashboard for your product, then the following code would be useful to achieve the required result.

<?php

/* Ingredients tab content */
function ingredients_tab_content_callback( $slug, $tab ) {
    ?>
	<h2><?php echo wp_kses_post( $tab['title'] ); ?></h2>
	<p><?php echo get_post_meta(get_the_ID(),'ingredients_information',true); ?></p>
	<?php
}
Was this article helpful?
YesNo

Leave a comment

Your email address will not be published. Required fields are marked *