Last active
December 30, 2023 20:19
-
-
Save finalwebsites/10cd065ac896576b0730161f15defbd4 to your computer and use it in GitHub Desktop.
Additional product tabs for your WooCommerce product pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.