id . '.3'; $quantity = rgget( $quantity_id, $value ); if ( $this->isRequired && rgblank( $quantity ) && ! $this->disableQuantity ) { $this->failed_validation = true; $this->validation_message = empty($this->errorMessage) ? esc_html__( 'This field is required.', 'gravityforms' ) : $this->errorMessage; } elseif ( ! empty( $quantity ) && ( ! is_numeric( $quantity ) || intval( $quantity ) != floatval( $quantity ) || intval( $quantity ) < 0 ) ) { $this->failed_validation = true; $this->validation_message = esc_html__( 'Please enter a valid quantity', 'gravityforms' ); } } public function get_value_default() { $value = array(); if ( is_array( $this->inputs ) ) { foreach ( $this->inputs as $index => $input ) { $input_value = $this->is_form_editor() ? rgar( $input, 'defaultValue' ) : GFCommon::replace_variables_prepopulate( rgar( $input, 'defaultValue' ) ); if ( rgblank( $input_value ) && $input['id'] == "{$this->id}.2" ) { $input_value = $this->basePrice; } $value[ strval( $input['id'] ) ] = $input_value; } } return $value; } public function get_field_input( $form, $value = '', $entry = null ) { $form_id = $form['id']; $is_entry_detail = $this->is_entry_detail(); $is_form_editor = $this->is_form_editor(); $id = (int) $this->id; $product_name = ! is_array( $value ) || empty( $value[ $this->id . '.1' ] ) ? esc_attr( $this->label ) : esc_attr( $value[ $this->id . '.1' ] ); $price = ! is_array( $value ) || empty( $value[ $this->id . '.2' ] ) ? $this->basePrice : esc_attr( $value[ $this->id . '.2' ] ); $quantity = is_array( $value ) ? esc_attr( $value[ $this->id . '.3' ] ) : ''; if ( rgblank( $quantity ) ) { $quantity = 1; } if ( empty( $price ) ) { $price = 0; } $price = esc_attr( $price ); $has_quantity_field = sizeof( GFCommon::get_product_fields_by_type( $form, array( 'quantity' ), $this->id ) ) > 0; if ( $has_quantity_field ) { $this->disableQuantity = true; } $quantity_field = $has_quantity_field ? '' : ""; $product_name_field = ""; $disabled_text = $is_form_editor ? 'disabled="disabled"' : ''; $field_type = $is_entry_detail || $is_form_editor ? 'text' : 'hidden'; return "
" . $quantity_field . $product_name_field . "
"; } /** * Format the entry value for display on the entry detail page and for the {all_fields} merge tag. * * @since 1.9 * @since 2.9.29 Changed the second parameter $currency (string) to $entry (array). * * @param string|array $value The field value. * @param array $entry The entry. * @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value. * @param string $format The format requested for the location the merge is being used. Possible values: html, text or url. * @param string $media The location where the value will be displayed. Possible values: screen or email. * * @return string */ public function get_value_entry_detail( $value, $entry = array(), $use_text = false, $format = 'html', $media = 'screen' ) { if ( is_array( $value ) && ! empty( $value ) ) { $product_name = trim( $value[ $this->id . '.1' ] ); $price = trim( $value[ $this->id . '.2' ] ); $quantity = trim( $value[ $this->id . '.3' ] ); $product_details = wp_kses( $product_name, wp_kses_allowed_html( 'data' ) ); if ( ! rgblank( $quantity ) ) { $product_details .= ', ' . esc_html__( 'Qty: ', 'gravityforms' ) . wp_kses( $quantity, wp_kses_allowed_html( 'data' ) ); } if ( ! rgblank( $price ) ) { $product_details .= ', ' . esc_html__( 'Price: ', 'gravityforms' ) . wp_kses( GFCommon::format_number( $price, 'currency', rgar( $entry, 'currency' ) ), wp_kses_allowed_html( 'data' ) ); } return $product_details; } else { return ''; } } public function sanitize_settings() { parent::sanitize_settings(); $price_number = GFCommon::to_number( $this->basePrice ); $this->basePrice = GFCommon::to_money( $price_number ); } } GF_Fields::register( new GF_Field_HiddenProduct() );