-
Notifications
You must be signed in to change notification settings - Fork 92
gpi-waiting-list.php: Fixed an issue where the waiting list message was not displaying correctly in entry views.
#1197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+162
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid - if ( $this->is_entry_item_waitlisted( $entry, $field, $value ) && strpos( $value, $this->waitlist_message ) === false ) {
+ $value_str = (string) $value;
+ if ( $this->is_entry_item_waitlisted( $entry, $field, $value_str ) && strpos( $value_str, $this->waitlist_message ) === false ) {
- $value .= ' ' . $this->waitlist_message;
+ $value_str .= ' ' . $this->waitlist_message;
}
- return $value;
+ return $value_str;
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+169
to
187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard This callback assumes (1) public function add_waitlist_message_to_product_info( $product_info, $form, $entry ) {
if ( ! $this->is_applicable_form( $form ) ) {
return $product_info;
}
+ if ( empty( $entry ) || ! is_array( $entry ) || empty( $entry['id'] ) ) {
+ return $product_info;
+ }
+
+ if ( empty( $product_info['products'] ) || ! is_array( $product_info['products'] ) ) {
+ return $product_info;
+ }
+
foreach ( $product_info['products'] as $field_id => &$product ) {
$field = GFAPI::get_field( $form, $field_id );
+ if ( ! $field ) {
+ continue;
+ }
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;
}
}
+ unset( $product );
return $product_info;
}Note: |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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 = '<div class="gpi-available-inventory-message" style="padding-bottom: 13px;">' . $message . '</div>' . $field->description; | ||||||||||||||||||||||||||||
| $message = $this->waitlist_message; | ||||||||||||||||||||||||||||
| if ( strpos( $field->description, $this->waitlist_message ) === false ) { | ||||||||||||||||||||||||||||
| $field->description = '<div class="gpi-available-inventory-message" style="padding-bottom: 13px;">' . $message . '</div>' . $field->description; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
276
to
+280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if ( $available <= 0 ) {
$message = $this->waitlist_message;
- if ( strpos( $field->description, $this->waitlist_message ) === false ) {
- $field->description = '<div class="gpi-available-inventory-message" style="padding-bottom: 13px;">' . $message . '</div>' . $field->description;
+ $description = (string) $field->description;
+ if ( strpos( $description, $this->waitlist_message ) === false ) {
+ $field->description = '<div class="gpi-available-inventory-message" style="padding-bottom: 13px;">' . esc_html( $message ) . '</div>' . $description;
}
$field->isWaitlisted = true;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| $field->isWaitlisted = true; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
cat -n gp-inventory/gpi-waiting-list.php | head -200Repository: gravitywiz/snippet-library
Length of output: 8795
🏁 Script executed:
Repository: gravitywiz/snippet-library
Length of output: 9008
🏁 Script executed:
rg "apply_filters.*gform_product_info|do_action.*gform_product_info" --type php -B 5 -A 5Repository: gravitywiz/snippet-library
Length of output: 52
🌐 Web query:
Gravity Forms gform_product_info hook documentation entry parameter💡 Result:
The gform_product_info filter receives three parameters: (1) $product_info (array), (2) $form (Form object), and (3) $entry — the Entry object for the entry being processed (examples sometimes name it $lead). [1]
Source: Gravity Forms docs for gform_product_info. [1]
🏁 Script executed:
Repository: gravitywiz/snippet-library
Length of output: 2439
🏁 Script executed:
Repository: gravitywiz/snippet-library
Length of output: 559
🏁 Script executed:
Repository: gravitywiz/snippet-library
Length of output: 831
🌐 Web query:
Gravity Forms gform_product_info hook when called contexts entry detail order summary💡 Result:
The gform_product_info filter is fired whenever Gravity Forms "requests the list of products saved in an entry" — i.e., any time GF builds the product/line‑item data for an entry. [1]
Typical contexts where it runs: Entry Detail order grid / order summary, the {all_fields} and {pricing_fields} merge tags (order summary output), notification/confirmation generation, and when Add‑Ons (e.g. PayPal) prepare product data to send. Use gform_order_summary / gform_product hooks to alter markup/labels. [2][3]
Important: gform_product_info applies when creating/assembling product data; it does NOT fire for already cached entry product data unless you clear that cached data first. [1]
Sources:
[1] Gravity Forms — gform_product_info documentation.
[2] Gravity Forms — gform_order_summary documentation.
[3] Gravity Forms — gform_product documentation.
🌐 Web query:
Gravity Forms gform_product_info preview mode draft entry null missing💡 Result:
Short answer: This is expected — gform_product_info runs when Gravity Forms "requests the list of products saved in an entry", but Preview / Save‑and‑Continue uses an incomplete (draft) submission where the cached entry/product data can be null, so the product list may be missing in preview mode. Use the Save & Continue filters or the preview init hook to rebuild/inject the product info for draft submissions before the preview renders. [1][2]
What to do (concise):
Minimal example (outline — adapt to your field IDs and form):
References:
If you want, paste your form ID and product field IDs and I’ll provide a ready‑to‑drop PHP snippet.
Add guards in
add_waitlist_message_to_product_info()for incomplete entry data in preview/draft contexts.The
gform_product_infohook can fire when processing incomplete entries (e.g., Save & Continue previews, draft submissions) where the entry structure may be incomplete or missing theidkey. The callback at line 169-187 immediately callsis_entry_item_waitlisted(), which accesses$entry['id']without checking if it exists. Add a guard before processing:public function add_waitlist_message_to_product_info( $product_info, $form, $entry ) { if ( ! $this->is_applicable_form( $form ) ) { return $product_info; } + if ( empty( $entry['id'] ) ) { + return $product_info; + }This prevents notices/fatals when the entry is not fully persisted.
🤖 Prompt for AI Agents