@@ -49,6 +49,9 @@ public function add_hooks() {
4949 add_filter ( 'gform_entries_field_value ' , array ( $ this , 'entries_field_value_with_waitlist_message ' ), 10 , 4 );
5050 add_filter ( 'gform_entry_field_value ' , array ( $ this , 'add_waitlist_message_to_entry_value ' ), 10 , 4 );
5151
52+ // Add support for order summary in entry details
53+ add_filter ( 'gform_product_info ' , array ( $ this , 'add_waitlist_message_to_product_info ' ), 10 , 3 );
54+
5255 /**
5356 * Single products
5457 */
@@ -134,35 +137,65 @@ public function apply_waitlist_message_to_choice( $choice, $field, $form, $how_m
134137 return $ choice ;
135138 }
136139
140+ private function is_entry_item_waitlisted ( $ entry , $ field , $ value ) {
141+ if ( gp_inventory_type_choices ()->is_applicable_field ( $ field ) ) {
142+ foreach ( $ field ->choices as $ choice ) {
143+ if ( $ choice ['text ' ] != $ value && $ choice ['value ' ] != $ value ) {
144+ continue ;
145+ }
146+ return (bool ) gform_get_meta ( $ entry ['id ' ], sprintf ( 'gpi_is_waitlisted_%d_%s ' , $ field ->id , sanitize_title ( $ choice ['value ' ] ) ) );
147+ }
148+ }
149+
150+ if ( gp_inventory_type_simple ()->is_applicable_field ( $ field ) || gp_inventory_type_advanced ()->is_applicable_field ( $ field ) ) {
151+ return (bool ) gform_get_meta ( $ entry ['id ' ], sprintf ( 'gpi_is_waitlisted_%d ' , $ field ->id ) );
152+ }
153+
154+ return false ;
155+ }
156+
137157 public function add_waitlist_message_to_entry_value ( $ value , $ field , $ entry , $ form ) {
138158 if ( ! $ this ->is_applicable_form ( $ form ) || ! $ this ->is_applicable_field ( $ field ) ) {
139159 return $ value ;
140160 }
141161
142- if ( gp_inventory_type_choices ()->is_applicable_field ( $ field ) ) {
143- foreach ( $ field ->choices as $ choice ) {
144- if ( $ choice ['text ' ] != $ value ) {
145- continue ;
146- }
162+ if ( $ this ->is_entry_item_waitlisted ( $ entry , $ field , $ value ) && strpos ( $ value , $ this ->waitlist_message ) === false ) {
163+ $ value .= ' ' . $ this ->waitlist_message ;
164+ }
147165
148- $ is_waitlisted = gform_get_meta ( $ entry ['id ' ], sprintf ( 'gpi_is_waitlisted_%d_%s ' , $ field ->id , sanitize_title ( $ choice ['value ' ] ) ) );
166+ return $ value ;
167+ }
149168
150- if ( $ is_waitlisted ) {
151- $ choice = $ this ->apply_waitlist_message_to_choice ( $ choice , $ field , $ form );
152- $ value = $ choice ['text ' ];
153- }
154- }
169+ public function add_waitlist_message_to_product_info ( $ product_info , $ form , $ entry ) {
170+ if ( ! $ this ->is_applicable_form ( $ form ) ) {
171+ return $ product_info ;
155172 }
156173
157- if ( gp_inventory_type_simple ()->is_applicable_field ( $ field ) || gp_inventory_type_advanced ()->is_applicable_field ( $ field ) ) {
158- $ is_waitlisted = gform_get_meta ( $ entry ['id ' ], sprintf ( 'gpi_is_waitlisted_%d ' , $ field ->id ) );
174+ if ( empty ( $ entry ) || ! is_array ( $ entry ) || empty ( $ entry ['id ' ] ) ) {
175+ return $ product_info ;
176+ }
177+
178+ if ( empty ( $ product_info ['products ' ] ) || ! is_array ( $ product_info ['products ' ] ) ) {
179+ return $ product_info ;
180+ }
159181
160- if ( $ is_waitlisted ) {
161- $ value .= ' ' . $ this ->waitlist_message ;
182+ foreach ( $ product_info ['products ' ] as $ field_id => &$ product ) {
183+ $ field = GFAPI ::get_field ( $ form , $ field_id );
184+ if ( ! $ field ) {
185+ continue ;
186+ }
187+
188+ if ( ! $ this ->is_applicable_field ( $ field ) ) {
189+ continue ;
190+ }
191+
192+ if ( $ this ->is_entry_item_waitlisted ( $ entry , $ field , $ product ['name ' ] ) && strpos ( $ product ['name ' ], $ this ->waitlist_message ) === false ) {
193+ $ product ['name ' ] .= ' ' . $ this ->waitlist_message ;
162194 }
163195 }
196+ unset( $ product );
164197
165- return $ value ;
198+ return $ product_info ;
166199 }
167200
168201 public function add_entry_meta ( $ entry , $ form ) {
@@ -253,8 +286,10 @@ public function add_waiting_list_to_single_product( $form ) {
253286 $ available = (int ) $ gpi_instance ->get_available_stock ( $ field );
254287
255288 if ( $ available <= 0 ) {
256- $ message = $ this ->waitlist_message ;
257- $ field ->description = '<div class="gpi-available-inventory-message" style="padding-bottom: 13px;"> ' . $ message . '</div> ' . $ field ->description ;
289+ $ message = $ this ->waitlist_message ;
290+ if ( strpos ( $ field ->description , $ this ->waitlist_message ) === false ) {
291+ $ field ->description = '<div class="gpi-available-inventory-message" style="padding-bottom: 13px;"> ' . $ message . '</div> ' . $ field ->description ;
292+ }
258293 $ field ->isWaitlisted = true ;
259294 }
260295 }
0 commit comments