Home › Forums › Add-ons › Repeater Field › Woocommerce custom tab conditional › Reply To: Woocommerce custom tab conditional
Hi @renee
Could you try this instead. I think it’s possible you could still use have_rows etc. for the looping of the repeater this just feels safer. Also I think your main issue was that you were looking if the_sub_field(‘product_pdf’) existed without first being in a loop (and the_* will always try to echo the results which is not desired when fetching a value for a variable).
<?php
add_filter( 'woocommerce_product_tabs', 'downloads_tab' );
function downloads_tab( $tabs ) {
// ensure ACF is available
if ( !function_exists( 'have_rows' ) )
return;
if ( get_field('downloads') ) {
$tabs[] = array(
'title' => 'Downloads',
'priority' => 15,
'callback' => 'show_download_content'
);
}
return $tabs;
}
function show_download_content() {
$downloads = get_field('downloads');
if( $downloads ):
// loop through the rows of data
foreach ( $downloads as $download ) :
// display a sub field value
echo '<p>'. $download['name_pdf'].'<.p>';
endwhile;
endif;
}
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.