Gravity Forms for Woocommerce Add-on – GF Products amount not calculated in cart

Has anyone had experience with the Gravity Forms for Woocommerce Add-on? Specifically when generating GF Product fields.

Here is what I am trying to accomplish:
Using a Woocommerce product, I’ve added ACF fields, so that my client can add/edit/disable menu items for a Build Your Own BBQ.

enter image description here

I use a gravity form and its filters to generate these menu items as GF products based on the ACF field values.

enter image description here

Using the Gravity Forms for Woocommerce Add-on, I use the Gravity Form with the Woocommerce product, so that it can be added to the cart and checkout.

enter image description here

When setting quantities, the product calculation is correctly totaled.

enter image description here

When added to cart, is where the issue is. The cart shows as $0.00, while the “product” is correct.

enter image description here

GF product fields work fine when added directly through the Gravity Forms wordpress UI. But I need to generate them via code. The Add-on developer has said that in theory it should work when done this way, but was not sure. Has anyone tried this before?

Here is the code I wrote to generate the GF Products (menu items):

add_filter( 'gform_pre_render_10', 'backyard_smokeout_products' );
add_filter( 'gform_pre_validation_10', 'backyard_smokeout_products' );
add_filter( 'gform_admin_pre_render_10', 'backyard_smokeout_products' );
add_filter( 'gform_pre_submission_filter_10', 'backyard_smokeout_products' );
function backyard_smokeout_products($form) {
    $counter = array();
    $new_fields = array();

    foreach ($form['fields'] as $field) {
        $counter[] = is_int($field->id) ? $field->id : 0;
    }

    $counter = max($counter) + 1;

    $section = array (
        'id' => $counter,
        'type'  => 'section',
        'label' => 'Add Sides to your Custom BBQ',
        'description'   => '(a minimum quantity of 4 is required for any item you order)',
    );
    $field = GF_Fields::create($section);
    array_push($new_fields, $field);
    $counter++;

    $sides = get_field('backyard_sides', 1122);

    if($sides) {
        foreach ($sides as $side) {
            if($side['side_enable'] == true) {
                $props = array (
                    'id' => $counter,
                    'label' => $side['side_name'],
                    'type'  => 'product',
                    'inputs' => array(
                        array(
                          'id'    => $counter.'.1',
                          'label' => 'Product Name',
                          'name'  => $side['side_name'],
                        ),
                        array(
                          'id'    => $counter.'.2',
                          'label' => 'Price',
                          'name'  => $side['side_price'],
                        ),
                        array(
                          'id'    => $counter.'.3',
                          'label' => 'Quantity',
                          'name'  => 'param_qty'
                        ),
                    ),
                    'basePrice' => $side['side_price'],
                    'inputType' => 'singleproduct',
                    'cssClass'  => 'side-item gf_inline',
                    'description' => $side['side_description'],
                );
                $field = GF_Fields::create( $props );
                array_push($new_fields, $field);
                $counter++;
            }      
        }
    }


    for ($i=0; $i < count($form['fields']); $i++) { 
        if ('This form is generated programmatically' == $form['fields'][$i]['label']) {
            array_splice( $form['fields'], $i + 1, 0, $new_fields );
            return $form;        
        }
    }
    return $form;
}

Go to Source
Author: Alexnl