How to Separate Product Selection and Price When Exporting Entries

By default, export columns which separate the product name and the product price are available for single product fields. However, these export columns are not available for product fields that present choices (i.e. with a field type of dropdown or radio buttons).

The following code block, when added to your site, will append options on your Export Entries screen for Product (Name), Product (Value), and Product (Price). These new columns will be available for all choice Product fields – including the Option and Shipping fields. It will also enable similar export columns (to show name and value) for Radio fields.

If you want to customize the heading labels in the export, this will also respect any Admin Labels you have set for the fields.

//Add export columns for label, value, and price of single choice fields
add_filter( 'gform_export_fields', function( $form ) {

   foreach ( $form['fields'] as $key => $field ) {

      $is_product_like_field = ( $field->type == 'product' || $field->type == 'option' || $field->type == 'shipping' ) ? true : false;

      if ( ( $is_product_like_field || $field->type == 'radio' ) && is_array( $field->choices ) ) {

         // unset( $form['fields'][ $key ] ); // uncomment to remove the original field from the export list

         // append our additional columns
         array_push( $form['fields'], array( 'id' => $field->id.'_text', 'label' => $field->label.' (Name)' ) );
         array_push( $form['fields'], array( 'id' => $field->id.'_value', 'label' => $field->label.' (Value)' ) );
         if ( $is_product_like_field ) {
            array_push( $form['fields'], array( 'id' => $field->id.'_price', 'label' => $field->label.' (Price)' ) );
         }

         // set the headers for each added column
         add_filter( "gform_entries_field_header_pre_export_{$form['id']}_{$field->id}_text", function( $header, $form, $export_field ) {
            return $header.' (Name)';
         }, 10, 3 );
         add_filter( "gform_entries_field_header_pre_export_{$form['id']}_{$field->id}_value", function( $header, $form, $export_field ) {
            return $header.' (Value)';
         }, 10, 3 );
         if ( $is_product_like_field ) {
            add_filter( "gform_entries_field_header_pre_export_{$form['id']}_{$field->id}_price", function( $header, $form, $export_field ) {
               return $header.' (Price)';
            }, 10, 3 );
         }

         // set the values for each added column
         add_filter( 'gform_export_field_value', function( $value, $form_id, $field_id, $entry ) use ( $field ) {

            $product_data = explode( '|', rgar( $entry, $field->id ) );
            $product_choice = array_filter( $field->choices, function( $choice ) use ( $product_data ) {
               return ( $choice['value'] == $product_data[0] );
            } );
            $product_choice = array_values( $product_choice );

            switch ( $field_id ) {
               case $field->id.'_text':
                  return $product_choice[0]['text'];
                  break;
               case $field->id.'_value':
                  return $product_data[0];
                  break;
               case $field->id.'_price':
                  return $product_data[1];
                  break;
               default:
                  return $value;
                  break;
            }

         }, 10, 4 );

      }

   }

   return $form;

} );

For additional information on the filters in use: