Skip to content

Commit 23a31e9

Browse files
committed
gpi-waiting-list.php: Added waiting list message on order summary page.
1 parent dc5b10d commit 23a31e9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

gp-inventory/gpi-waiting-list.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function add_hooks() {
6666

6767
// Allow negative stock to be used for conditional logic validation.
6868
add_filter( 'gpi_allow_negative_stock', array( $this, 'allow_negative_stock_for_conditional_logic' ), 10, 3 );
69+
70+
add_filter( 'gform_order_summary', array( $this, 'add_waiting_list_to_order_summary' ), 11, 3 );
6971
}
7072

7173
public function is_applicable_form( $form ) {
@@ -270,6 +272,39 @@ public function allow_negative_stock_for_conditional_logic( $allow_negative_stoc
270272
return true;
271273
}
272274

275+
public function add_waiting_list_to_order_summary( $markup, $form, $entry ) {
276+
if ( empty( $entry ) ) {
277+
return $markup;
278+
}
279+
280+
$products = GFCommon::get_product_fields( $form, $entry );
281+
if ( empty( $products['products'] ) ) {
282+
return $markup;
283+
}
284+
285+
libxml_use_internal_errors( true );
286+
$dom = new DOMDocument();
287+
$dom->loadHTML( mb_convert_encoding( $markup, 'HTML-ENTITIES', 'UTF-8' ) );
288+
289+
$xpath = new DOMXPath( $dom );
290+
$productNodes = $xpath->query( "//div[contains(@class, 'product_name')]" );
291+
foreach ( $productNodes as $node ) {
292+
foreach ( $products['products'] as $product_id => $product ) {
293+
if ( $product['name'] == $node->nodeValue ) {
294+
$field = GFAPI::get_field( $form, $product_id );
295+
$gpi_instance = gp_inventory_type_simple()::$type === rgar( $field, 'gpiInventory' ) ? gp_inventory_type_simple() : gp_inventory_type_advanced();
296+
$available = (int) $gpi_instance->get_available_stock( $field );
297+
if ( $available <= 0 ) {
298+
$node->nodeValue .= $this->waitlist_message;
299+
}
300+
break;
301+
}
302+
}
303+
}
304+
305+
$markup = $dom->saveHTML();
306+
return $markup;
307+
}
273308
}
274309

275310
new GPI_Waiting_List();

0 commit comments

Comments
 (0)