Support

Account

Home Forums Front-end Issues Adding a field group to new product tab

Helping

Adding a field group to new product tab

  • Hi,

    I hope I’m not repeating the question, but so far I wasnt able to find an answer.

    I created a new field group with custom field for product information and I’m able to fill product with data in the back end.

    How can I display the data from this field group to a new tab on the product page?

    I’m tried adding this code to child theme’s function.php but isn’t working:

    
    
    /**
     * Add a custom product data tab
     */
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
    	
    	// Adds the new tab
    	
    	$tabs['test_tab'] = array(
    		'title' 	=> __( 'New Product Tab', 'woocommerce' ),
    		'priority' 	=> 50,
    		'callback' 	=> 'woo_new_product_tab_content'
    	);
    
    	return $tabs;
    
    }
    function woo_new_product_tab_content() {
    
    	// The new tab content
    
    	echo '<h2>Additional Information</h2>';
    	echo '<p>Product additional info:</p>';
    
    $group_ID = 3680;
    
    $fields = array();
    $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    
    if( $fields )
    {
    	foreach( $fields as $field )
    	{
    		$value = get_field( $field['name'] );
    		
    		echo '<dl>';
    			echo '<dt>' . $field['label'] . '</dt>';
    			echo '<dd>' .$value . '</dd>';
    		echo '</dl>';
    	}
    }
    
    }
    
    ?>
    
  • I didn’t think it was possible with just a function. I’ve just been editing/creating the template files for it.

    So in your child theme folder create a sub folder called woocommerce then another sub folder called single-product then inside that another sub folder called tabs.

    You can duplicate the files over from the woocommerce plugin, it follows the same file suture. And rename one of the duplicates to your-tab-title.php and there you can pull the data in from ACF.

    Also dupliate the tab.php over and add in the new title for that tab too in there

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.