Skip to content

Commit 9359c60

Browse files
gspc-errors-directly-above-gf.php: Added new snippet.
1 parent 0394642 commit 9359c60

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Gravity Shop // GS Product Configurator // Move validation errors to be directly above product Gravity Form.
4+
* https://gravitywiz.com/documentation/gravity-shop-product-configurator/
5+
*
6+
* By default, Gravity Shop Product Configurator will display validation errors at the very top of the form used
7+
* to configure a product. This means it would be above any variations and other controls provided by WooCommerce
8+
* and other WooCommerce extensions.
9+
*
10+
* Instructions:
11+
* Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
12+
*/
13+
add_filter( 'gform_get_form_filter', function( $markup, $form ) {
14+
if ( ! function_exists( 'gs_product_configurator' ) || ! gs_product_configurator()->should_enqueue_frontend( $form ) ) {
15+
return $markup;
16+
}
17+
18+
$pattern = '/<div class="gform_validation_errors" ([\s\S]+?)<\/div>/';
19+
$pattern2 = '/(<div class=(["\'])gform[-_]body)/';
20+
if ( preg_match($pattern, $markup, $matches ) ) {
21+
$markup = preg_replace( $pattern, '', $markup );
22+
$markup = preg_replace( $pattern2, $matches[0] . '$1', $markup );
23+
}
24+
return $markup;
25+
}, 10, 2 );

0 commit comments

Comments
 (0)