Ecommerce Shopify WordPress Discussion

Display Custom WooCommerce Product tab with ACF repeater fields if subfields exists

I have a custom snippet to display a custom tab on the product page. The content is ACF file fields with repeater field. It works fine, when I set the files for the product, they all appear on the product page the way I want them to. I would like that if no file is specified, the tab should not appear either. Here is the code I use: add_filter( 'woocommerce_product_tabs', 'woostify_custom_tab' ); function woostify_custom_tab( $tabs ) { if( get_field('letoltheto_katalogusok') ) { $tabs['tab-catalogues'] = array( 'title' => 'Letölthető katalógus', 'callback' => 'woostify_custom_tab_content', 'priority' => 25, ); } return $tabs; } function woostify_custom_tab_content( $slug, $tab ) { if (have_rows('letoltheto_katalogusok')) { while (have_rows('letoltheto_katalogusok')) { the_row(); $file = get_sub_field('letoltheto_katalogus'); $file2 = get_sub_field('letoltheto_katalogusa'); $file3 = get_sub_field('letoltheto_katalogusb'); ?> <br> <div class="katalogusok"> <a href="<?php echo $file['url']; ?>" target="_blank" ><?php echo $file['filename']; ?></a> <a href="<?php echo $file2['url']; ?>" target="_blank" ><?php echo $file2['filename']; ?></a> <a href="<?php echo $file3['url']; ?>" target="_blank" ><?php echo $file3['filename']; ?></a> </div> <?php } } } Anyone have any ideas?
Do the same thing with the part that adds the tab, as you did in the code that is supposed to actually fill the tab - use have_rows('letoltheto_katalogusok') to check if the repeater actually contains anything to loop over. function woostify_custom_tab( $tabs ) { if( have_rows('letoltheto_katalogusok') ) { $tabs['tab-catalogues'] = array( 'title' => 'Letölthető katalógus', 'callback' => 'woostify_custom_tab_content', 'priority' => 25, ); } return $tabs; } Note that have_rows is "dynamic", it will return false once all rows have been iterated over (that's why it can terminate the while loop, once all rows have been output.) But since at this point you are not iterating over the rows, it will still hold the same initial true or false value, when it gets to your loop in the woostify_custom_tab_content function.

January 27, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.