Home › Forums › Backend Issues (wp-admin) › Snippet for Custom Field to Display in Product Tab › Reply To: Snippet for Custom Field to Display in Product Tab
Hi @igeeksupport ,
It is becuase our fields are not text but has options.
Here is right code which worked for me.
You can change EAN and Brand according to your fields names.
/**
* Add the custom tab
*/
function my_simple_custom_product_tab( $tabs ) {
// Adds the new tab
if(get_field('ean')) //if there is custom field for this product, then show this tab
$tabs['my_custom_tab'] = array(
'title' => __( 'Bran and EAN', 'textdomain' ), //You can change Brand and EAN as you wish
'callback' => 'my_simple_custom_tab_content',
'priority' => 50,
);
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'my_simple_custom_product_tab' );
/**
* Function that displays output for the tab.
*/
function my_simple_custom_tab_content($slug, $tab ) {
?><h2><?php echo wp_kses_post( $tab['title'] ); ?></h2>
<?php
$brand= get_field_object('brand');
$ean= get_field_object('ean');
echo '<p>' . $brand['label']. ' : '. $brand['value'] .'</p>';
echo '<p>' . $ean['label']. ' : '. $ean['value'] .'</p>';
}
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.