Home › Forums › Front-end Issues › Add custom fields to custom product tabs › Reply To: Add custom fields to custom product tabs
My apologies – I didn’t include all of the code, just the portion that I thought was relevant.
Yes, I had created a custom tab in my child’s function.php file:
/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'specifications_custom_tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'specifications_custom_tab'
);
return $tabs;
}
function specifications_custom_tab() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
Then I added this code straight after:
add_action('specifications_custom_tab', 'display_product_fields' );
function display_product_fields() {
$fields = get_field_objects();
if( $fields ): ?>
<ul>
<?php foreach( $fields as $field ): ?>
<li><?php echo $field['label']; ?>: <?php echo $field['value']; ?></li>
<?php endforeach; ?>
</ul>
<?php endif;
}?>
The code to add custom product fields to my custom tab (or any tab for that matter) didn’t work. Am I doing something wrong?
Thank you again for all your help!
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.