Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active December 30, 2023 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/10cd065ac896576b0730161f15defbd4 to your computer and use it in GitHub Desktop.
Save finalwebsites/10cd065ac896576b0730161f15defbd4 to your computer and use it in GitHub Desktop.
Additional product tabs for your WooCommerce product pages
<?php
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
function woo_custom_product_tabs( $tabs ) {
// Shipment info tab
$tabs['fw_shipment_tab'] = array(
'title' => __( 'Shipment info', 'woocommerce' ),
'priority' => 100, // use a higher value and move the tab to the end
'callback' => 'fw_shipment_tab_content'
);
}
function fw_shipment_tab_content() {
echo '<h2>Additional shipment information</h2>';
echo '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean tempus, metus ut dignissim accumsan, arcu sem tristique lectus, in vestibulum quam eros vel nisi.
Proin et viverra ligula.</p>';
}
<?php
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
function woo_custom_product_tabs( $tabs ) {
// Shipment info tab
$enabled = get_field('enable_tab');
if ($enabled) {
$title = get_field('tab_title');
$tabs['fw_shipment_tab'] = array(
'title' => __( $title, 'woocommerce' ),
'priority' => 100, // use a higher value and move the tab to the end
'callback' => 'fw_shipment_tab_content'
);
}
}
function fw_shipment_tab_content() {
the_field('tab_content');
}
@finalwebsites
Copy link
Author

finalwebsites commented Dec 26, 2023

The code belongs into your child theme's function.php file. The first is a static function and the second is for people using Advanced Custom Fields (ACF) for dynamic function.
Add more $tabs array elements, If you need multiple tabs. Use unique array keys and create a callback function foreach new tab your create.

For the ACF users:
Create a field group with the 3 different fields and "connect" them to the product post type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment