Support

Account

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;
    }