Support

Account

Forum Replies Created

  • From a rendering perspective, the field group within Woocommerce looks pretty bad but can probably be fixed up with custom CSS. I’m kind of surprised there isn’t already more support for using both of these 2 pretty popular plugins together.

  • No, both traditional ACF field group and ACF group added into Woocommerce do not contain the same field(s). I’ve found that you need to manually save the ACF fields within woocommerce_process_product_meta. Feels a little dirty, but it works.

        add_action( 'woocommerce_product_options_general_product_data', function() {
            acf_form([
                'post_id' => get_the_ID(),
                'field_groups' => [233],
                'form' => false,
            ]); 
        });
    
        add_action( 'woocommerce_process_product_meta', function($post_id) {
            if (!empty($_POST['acf'])) {
                foreach($_POST['acf'] as $key => $value) {
                    update_field($key, $value, $post_id);
                }
            }
        });
  • Gave it a shot. With the code below custom field data is not saved from the embedded field group. I’m also noticing ACF fields in other groups (added to the post type the normal way) is also not saved. When the Woocommerce code is removed other field group does save.

        add_action( 'woocommerce_product_options_general_product_data', function() {
            echo '<div class="options_group">';        
            acf_form([
                'field_groups' => [233],
                'form' => false,
            ]); 
            echo '</div>';
        });
  • Oh interesting, let me give that a shot. Will this take care of saving the values too when the page is submitted?

  • Looks like my IMG link had stopped working. I’ve updated parent post with correct IMG embed.

    Anyone have any experience or advice on how this could be accomplished?

  • Hello, wondering if you were able to test this out. It’s nice to know the JSON is an option but I would prefer to define my field group in PHP. Thanks for the help.

  • I’m using the JSON actually to cache my groups. But I thought everytime you make changes locally and push up you have to manually go into the backend and click to refresh the group (circle arrow icon)?

    GROUP (truncated example):

    
    if( function_exists('acf_add_local_field_group') ):
    
    acf_add_local_field_group(array(
        'key' => 'group_597a31e9a49bd2',
        'title' => 'Settings (New)',
        'fields' => array(
            array(
                'key' => 'field_597a32a719ca9',
                'label' => 'Co-Chairs',
                'name' => 'co-chairs',
                'type' => 'repeater',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'collapsed' => 'field_597a32da19caa',
                'min' => 0,
                'max' => 0,
                'layout' => 'table',
                'button_label' => 'Add Co-Chair',
                'sub_fields' => array(
                    array(
                        'key' => 'field_597a32da19caa',
                        'label' => 'Name',
                        'name' => 'name',
                        'type' => 'text',
                        'instructions' => '',
                        'required' => 0,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'default_value' => '',
                        'placeholder' => '',
                        'prepend' => '',
                        'append' => '',
                        'maxlength' => '',
                    ),
                    array(
                        'key' => 'field_597a32e719cab',
                        'label' => 'Affiliate',
                        'name' => 'affiliate',
                        'type' => 'text',
                        'instructions' => '',
                        'required' => 0,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'default_value' => '',
                        'placeholder' => '',
                        'prepend' => '',
                        'append' => '',
                        'maxlength' => '',
                    ),
                    array(
                        'key' => 'field_597a32fe19cac',
                        'label' => 'E-Mail',
                        'name' => 'e-mail',
                        'type' => 'email',
                        'instructions' => '',
                        'required' => 0,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'default_value' => '',
                        'placeholder' => '',
                        'prepend' => '',
                        'append' => '',
                    ),
                ),
            ),
            
        ),
        'location' => array(
            array(
                array(
                    'param' => 'page_template',
                    'operator' => '==',
                    'value' => 'page-committee-info.php',
                ),
            ),
        ),
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
        'active' => 1,
        'description' => '',
    ));
    
    endif;

    TEMPLATE:

        <? if ( get_field( 'co-chairs', $settings_page) ) : ?>
        <li>
    
            <? var_dump( $settings_page ); ?>
    
            <h2 class="subheader-small">Co Chairs</h2>
            <ul class="co-chairs">
                <?php while( have_rows('co-chairs', $settings_page) ): the_row(); ?>
    
                <li>
                    <div class="name"><?=get_sub_field('name'); ?></div>
                    <div class="Preheader affiliate"><?=get_sub_field('affiliate'); ?></div>
                    <div class="Preheader email"><a href="mailto:<?=get_sub_field('e-mail'); ?>"><?=the_sub_field('e-mail'); ?></a></div>                           
                </li>
                <? endwhile; ?>
            </ul>
        </li>
        <? endif; ?>
  • I know this is a super old thread, but thought I would share my improvements to the solution above.

    – I’m hiding the content with CSS at first to prevent page jump and them being momentarily visible while the page loads. This CSS is then removed once JS has been applied.
    – Just adding the -collapsedclass to .layout was making other elements on the page (like metaboxes) also collapse.

        function ACF_flexible_content_collapse() {
            ?>
            <style id="acf-flexible-content-collapse">.acf-flexible-content .acf-fields { display: none; }</style>
            <script type="text/javascript">
                jQuery(function($) {
                    $('.acf-flexible-content .layout').addClass('-collapsed');
                    $('#acf-flexible-content-collapse').detach();
                });
            </script>
            <?php
        }
    
        add_action('acf/input/admin_head', 'ACF_flexible_content_collapse');
Viewing 9 posts - 1 through 9 (of 9 total)