GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
field-product-html.php
Go to the documentation of this file.
1 <?php
2 /**
3  * The default product field output template.
4  *
5  * @global \GV\Template_Context $gravityview
6  * @since 2.0
7  */
8 
9 if ( ! isset( $gravityview ) || empty( $gravityview->template ) ) {
10  gravityview()->log->error( '{file} template loaded without context', array( 'file' => __FILE__ ) );
11  return;
12 }
13 
14 $field_id = $gravityview->field->ID;
15 $value = $gravityview->value;
16 $display_value = $gravityview->display_value;
17 if ( '' == $display_value ) {
19 }
20 $entry = $gravityview->entry->as_entry();
21 
22 /**
23  * See if there are any values in the product array GF provides. (product name, quantity, price)
24  *
25  * If not, Gravity Forms displays a useless string (", Qty: , Price:") instead of an empty value. This prevents
26  * the "Hide empty fields" setting from working.
27  *
28  * @since 1.12
29  */
30 $value = is_array( $value ) ? array_filter( $value, 'gravityview_is_not_empty_string' ) : $value;
31 
32 // If so, then we have something worth showing
33 if ( ! empty( $value ) ) {
35 
36  /**
37  * If a product has 0 quantity, don't output any of it.
38  * https://github.com/gravityview/GravityView/issues/1263
39  *
40  * @since develop
41  */
42  $hide_empty_products = ! in_array( $gravityview->field->inputType, array( 'select', 'radio', 'price', 'hidden' ) );
43 
44  if ( $hide_empty_products && $gravityview->view->settings->get( 'hide_empty' ) ) {
45  $_field_id = intval( $field_id );
46 
47  $quantity_found = false;
48 
49  foreach ( $gravityview->fields->all() as $_field ) {
50  if ( $_field->type == 'quantity' ) {
51  if ( $_field->productField == $_field_id ) {
52  $quantity_found = ! empty( $entry[ $_field->ID ] );
53  break;
54  }
55  }
56  }
57 
58  if ( ! $quantity_found && ! $gravityview->field->disableQuantity && empty( $entry[ "$_field_id.3" ] ) ) {
59  return;
60  }
61  }
62 
64 
65  /**
66  * The old format used the store the data as Product|Price|Quantity.
67  * See if we can detect this and save the day.
68  */
69  if ( $input_id && ! isset( $entry[ $field_id ] ) ) {
70  $value = explode( '|', $value );
71 
72  if ( isset( $value[ $input_id - 1 ] ) ) {
73  $output = $value[ $input_id - 1 ];
74  }
75  }
76 
77  switch ( $input_id ) {
78  case 2:
79  $output = GFCommon::to_money( $output, \GV\Utils::get( $entry, 'currency' ) );
80  break;
81  case 3:
82  $output = GFCommon::to_number( $output );
83  break;
84  default:
85  $output = esc_html( $output );
86  break;
87  }
88 
89  echo $output;
90 }
gravityview_get_field_value( $entry, $field_id, $display_value)
Handle getting values for complex Gravity Forms fields.
Definition: class-api.php:1034
$value
See if there are any values in the product array GF provides.
gravityview_get_input_id_from_id( $field_id='')
Very commonly needed: get the # of the input based on a full field ID.
if(! isset( $gravityview)||empty( $gravityview->template)) $field_id
The default product field output template.
$display_value
gravityview()
The main GravityView wrapper function.
if(''==$display_value) $entry