Home › Forums › Add-ons › Repeater Field › Determine if a Sub Field with a specific title is present › Reply To: Determine if a Sub Field with a specific title is present
I wonder if you need to use the woo product TAB callback.
So something like:
<?php
########################
# Add Custom Product Page TAB
########################
add_filter( 'woocommerce_product_tabs', 'acf_woo_new_product_tab' );
function acf_woo_new_product_tab( $tabs ) {
global $product;
$product_id = $product->get_id();
if( have_rows('details_repeater',$product_id ) ):
while( have_rows('details_repeater',$product_id ) ) : the_row();
if (get_sub_field('title') == 'Characteristics') :
// Adds the new tab
$tabs['product_details_tab'] = array(
'title' => __( 'Characteristics', 'woocommerce' ),
'priority' => 10,
'callback' => 'acf_product_details_tab_content'
);
endif;
endwhile;
endif;
return $tabs;
}
function acf_product_details_tab_content() {
global $product;
$product_id = $product->get_id();
// Check rows exists.
if( have_rows('details_repeater',$product_id ) ):
echo '<h2>Characteristics</h2>';
// Loop through rows.
while( have_rows('details_repeater',$product_id ) ) : the_row();
// Load sub field value.
$content = get_sub_field('content');
echo $content;
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
}
Code is untested but hopefully, you can see what’s happening.
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.