Support

Account

Home Forums Front-end Issues Issue with getting ACF-group field in single-product.php (Woocommerce)

Solving

Issue with getting ACF-group field in single-product.php (Woocommerce)

  • I added this code:

    <?php
    /*
    *  get all custom fields and dump for testing
    */
    $fields = get_field_objects();
    var_dump( $fields ); 
    /*
    *  get all custom fields, loop through them and create a label => value markup
    */
    $fields = get_field_objects();
    if( $fields )
    {
    	foreach( $fields as $field_name => $field )
    	{
    		echo '<div>';
    			echo '<h3>' . $field['label'] . '</h3>';
    			echo $field['value'];
    		echo '</div>';
    	}
    }
    ?>

    from http://www.advancedcustomfields.com/resources/get_field_objects/
    but, page looks so:
    issue acf in single-product.php

    If you please, help me with it.
    P.S. The whole single-product.php in attachment

  • You’re getting Array because they’re not all strings. You can convert those to a string like this:

    $fields = get_field_objects();
    if( $fields )
    {
    	foreach( $fields as $field_name => $field )
    	{
    		echo '<div>';
    			echo '<h3>' . $field['label'] . '</h3>';
    			
    			if ( is_array( $field['value'] ) )
    			{
    				echo implode( ', ', $field['value'] );
    			}
    			else
    			{
    				echo $field['value'];
    			}
    
    		echo '</div>';
    	}
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Issue with getting ACF-group field in single-product.php (Woocommerce)’ is closed to new replies.