Home › Forums › General Issues › Adding WooCommerce tabs › Reply To: Adding WooCommerce tabs
So it turns out that all fields show up if I make sure the “key” is different.
But now I need to show my tabs, and this code, which should display the new tabs, does not (even when I ensure a tab has content in it):
if (class_exists('acf') && class_exists('WooCommerce')) {
add_filter('woocommerce_product_tabs', function($tabs) {
global $post, $product; // Access to the current product or post
$custom_tab_title = get_field('tab_title', $post->ID);
if (!empty($custom_tab_title)) {
$tabs['awp-' . sanitize_title($custom_tab_title)] = [
'title' => $custom_tab_title,
'callback' => 'awp_custom_woocommerce_tabs',
'priority' => 10
];
}
return $tabs;
});
function awp_custom_woocommerce_tabs($key, $tab) {
global $post;
?><h2><?php echo $tab['title']; ?></h2><?php
$custom_tab_contents = get_field('tab_contents', $post->ID);
echo $custom_tab_contents;
}
}
Any advice is much appreciated!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.