From f7c1912083170050b9c7390699e828d9dde67d0b Mon Sep 17 00:00:00 2001 From: Sebastian Pedersen Date: Thu, 11 Dec 2025 23:18:06 -0800 Subject: [PATCH] `gpi-waiting-list.php`: Fixed an issue where the waiting list message was not displaying correctly in entry views. --- gp-inventory/gpi-waiting-list.php | 59 +++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/gp-inventory/gpi-waiting-list.php b/gp-inventory/gpi-waiting-list.php index 9cdd6ae4f..284e74373 100644 --- a/gp-inventory/gpi-waiting-list.php +++ b/gp-inventory/gpi-waiting-list.php @@ -49,6 +49,9 @@ public function add_hooks() { add_filter( 'gform_entries_field_value', array( $this, 'entries_field_value_with_waitlist_message' ), 10, 4 ); add_filter( 'gform_entry_field_value', array( $this, 'add_waitlist_message_to_entry_value' ), 10, 4 ); + // Add support for order summary in entry details + add_filter( 'gform_product_info', array( $this, 'add_waitlist_message_to_product_info' ), 10, 3 ); + /** * Single products */ @@ -134,35 +137,53 @@ public function apply_waitlist_message_to_choice( $choice, $field, $form, $how_m return $choice; } + private function is_entry_item_waitlisted( $entry, $field, $value ) { + if ( gp_inventory_type_choices()->is_applicable_field( $field ) ) { + foreach ( $field->choices as $choice ) { + if ( $choice['text'] != $value && $choice['value'] != $value ) { + continue; + } + return (bool) gform_get_meta( $entry['id'], sprintf( 'gpi_is_waitlisted_%d_%s', $field->id, sanitize_title( $choice['value'] ) ) ); + } + } + + if ( gp_inventory_type_simple()->is_applicable_field( $field ) || gp_inventory_type_advanced()->is_applicable_field( $field ) ) { + return (bool) gform_get_meta( $entry['id'], sprintf( 'gpi_is_waitlisted_%d', $field->id ) ); + } + + return false; + } + public function add_waitlist_message_to_entry_value( $value, $field, $entry, $form ) { if ( ! $this->is_applicable_form( $form ) || ! $this->is_applicable_field( $field ) ) { return $value; } - if ( gp_inventory_type_choices()->is_applicable_field( $field ) ) { - foreach ( $field->choices as $choice ) { - if ( $choice['text'] != $value ) { - continue; - } + if ( $this->is_entry_item_waitlisted( $entry, $field, $value ) && strpos( $value, $this->waitlist_message ) === false ) { + $value .= ' ' . $this->waitlist_message; + } - $is_waitlisted = gform_get_meta( $entry['id'], sprintf( 'gpi_is_waitlisted_%d_%s', $field->id, sanitize_title( $choice['value'] ) ) ); + return $value; + } - if ( $is_waitlisted ) { - $choice = $this->apply_waitlist_message_to_choice( $choice, $field, $form ); - $value = $choice['text']; - } - } + public function add_waitlist_message_to_product_info( $product_info, $form, $entry ) { + if ( ! $this->is_applicable_form( $form ) ) { + return $product_info; } - if ( gp_inventory_type_simple()->is_applicable_field( $field ) || gp_inventory_type_advanced()->is_applicable_field( $field ) ) { - $is_waitlisted = gform_get_meta( $entry['id'], sprintf( 'gpi_is_waitlisted_%d', $field->id ) ); + foreach ( $product_info['products'] as $field_id => &$product ) { + $field = GFAPI::get_field( $form, $field_id ); - if ( $is_waitlisted ) { - $value .= ' ' . $this->waitlist_message; + if ( ! $this->is_applicable_field( $field ) ) { + continue; + } + + if ( $this->is_entry_item_waitlisted( $entry, $field, $product['name'] ) && strpos( $product['name'], $this->waitlist_message ) === false ) { + $product['name'] .= ' ' . $this->waitlist_message; } } - return $value; + return $product_info; } public function add_entry_meta( $entry, $form ) { @@ -253,8 +274,10 @@ public function add_waiting_list_to_single_product( $form ) { $available = (int) $gpi_instance->get_available_stock( $field ); if ( $available <= 0 ) { - $message = $this->waitlist_message; - $field->description = '
' . $message . '
' . $field->description; + $message = $this->waitlist_message; + if ( strpos( $field->description, $this->waitlist_message ) === false ) { + $field->description = '
' . $message . '
' . $field->description; + } $field->isWaitlisted = true; } }