Skip to content

Commit

Permalink
gspc-errors-directly-above-gf.php: Added new snippet.
Browse files Browse the repository at this point in the history
  • Loading branch information
claygriffiths authored Oct 30, 2024
1 parent 0394642 commit 9359c60
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gs-product-configurator/gspc-errors-directly-above-gf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Gravity Shop // GS Product Configurator // Move validation errors to be directly above product Gravity Form.
* https://gravitywiz.com/documentation/gravity-shop-product-configurator/
*
* By default, Gravity Shop Product Configurator will display validation errors at the very top of the form used
* to configure a product. This means it would be above any variations and other controls provided by WooCommerce
* and other WooCommerce extensions.
*
* Instructions:
* Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
*/
add_filter( 'gform_get_form_filter', function( $markup, $form ) {
if ( ! function_exists( 'gs_product_configurator' ) || ! gs_product_configurator()->should_enqueue_frontend( $form ) ) {
return $markup;
}

$pattern = '/<div class="gform_validation_errors" ([\s\S]+?)<\/div>/';

Check warning on line 18 in gs-product-configurator/gspc-errors-directly-above-gf.php

View workflow job for this annotation

GitHub Actions / PHPCS

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
$pattern2 = '/(<div class=(["\'])gform[-_]body)/';
if ( preg_match($pattern, $markup, $matches ) ) {

Check failure on line 20 in gs-product-configurator/gspc-errors-directly-above-gf.php

View workflow job for this annotation

GitHub Actions / PHPCS

Expected 1 spaces after opening parenthesis; 0 found
$markup = preg_replace( $pattern, '', $markup );
$markup = preg_replace( $pattern2, $matches[0] . '$1', $markup );
}
return $markup;
}, 10, 2 );

0 comments on commit 9359c60

Please sign in to comment.