Skip to content

Instantly share code, notes, and snippets.

View claygriffiths's full-sized avatar

Clay Griffiths claygriffiths

View GitHub Profile
@claygriffiths
claygriffiths / gwiz-validate-html-field-in-form-editor.js
Created September 27, 2023 20:22
GWiz: Validate HTML Fields in Form Editor
// Paste this into your browser DevTools console while editing a form in Gravity Forms
// Load fast-xml-parser
jQuery.getScript(
"https://cdnjs.cloudflare.com/ajax/libs/fast-xml-parser/4.0.8/fxparser.js",
function () {
// Loop through HTML fields in window.form.fields
window.form.fields.forEach(function (field) {
if (field.type !== "html") {
return;
}
@claygriffiths
claygriffiths / sticky-scrollbar.css
Last active August 7, 2023 17:17
Gravity Wiz Redesign: Sticky Scrollbar
.table-of-contents {
position: sticky;
top: 2.25rem;
overflow-y: auto;
max-height: calc(100vh - 2.25rem);
margin-top: 2.25rem;
padding-bottom: 2.25rem;
box-sizing: border-box;
}
@claygriffiths
claygriffiths / gspc-map-form-fields-to-checkout.php
Created August 4, 2023 21:45
GS Product Configurator: Map form fields to checkout
<?php
add_filter('woocommerce_checkout_get_value', function( $input, $key ) {
// Get current items in the cart.
$cart_items = WC()->cart->get_cart();
// Loop through cart items.
foreach ( $cart_items as $cart_item ) {
// Convert to a GSPC Cart Item
$gspc_cart_item = \GS_Product_Configurator\WC_Cart_Item::from( $cart_item );
@claygriffiths
claygriffiths / gspc-populate-field-with-order-id.php
Last active October 22, 2024 22:08
GS Product Configurator: Populate Field with Order ID
<?php
/**
* Gravity Shop // GS Product Configurator // Populate Gravity Forms field with WooCommerce Order ID
*
* Populate fields in a Gravity Form that is linked to a WooCommerce product using GS Product Configurator
* with the WooCommerce order ID after checking out.
*
* Credit: Rochelle Victor (https://github.com/rochekaid)
*
* Instructions:
@claygriffiths
claygriffiths / gfoai-fine-tuned-sep.php
Created December 27, 2022 20:51
Gravity Forms OpenAI: Custom Separator for Fine-Tuned Models
<?php
/**
* Gravity Wiz // Gravity Forms OpenAI // Add separator to prompt
* https://gravitywiz.com/path/to/article/
*
* Adds a separator to a prompt if needed by a fine-tuned model.
*
* Instructions:
* 1. Customize $model and $sep accordingly.
*/
@claygriffiths
claygriffiths / gpns-custom-recurring-schedule.php
Last active March 8, 2022 20:00
GP Notification Scheduler: Set Recurring Schedule to Every 6 Months
<?php
/**
* Gravity Perks // GP Notification Scheduler // Set Recurring Schedule to Every 6 Months
* https://gravitywiz.com/documentation/gravity-forms-notification-scheduler
*
* Instructions:
* * Install snippet per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
* * Update $form_id, $notification_id, and if required, $desired_time
*/
add_filter( 'gpns_schedule_timestamp', function ( $timestamp, $notification, $entry, $is_recurring, $current_time ) {
@claygriffiths
claygriffiths / gpaa-autocomplete-cities.js
Created March 8, 2022 01:43
GP Address Autocomplete: Show Cities as Results
/**
* Gravity Perks // GP Address Autocomplete // Show Cities as Results
* https://gravitywiz.com/documentation/gravity-forms-address-autocomplete
*
* Instructions:
* 1. Install our free Custom JavaScript for Gravity Forms plugin.
* Download the plugin here: https://gravitywiz.com/gravity-forms-custom-javascript/
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
* 3. Install accompanying gpaa-autocomplete-cities.php snippet
*/
@claygriffiths
claygriffiths / gf-get-field-by-label.php
Created December 16, 2021 17:28
Gravity Forms: Get Field by Label
<?php
/**
* Get Gravity Forms Field by Label
* @link https://gravitywiz.com
*
* @param array|int $form_or_id The Form Object or ID.
* @param string $search The field label to search by.
* @param string $label_property The property from the field to search using. Defaults to "label". Set to "adminLabel"
* to search by the admin label.
*
@claygriffiths
claygriffiths / gf-auto-check-checkboxes.js
Created November 11, 2021 03:11
Gravity Forms: Automatically Check Checkbox
/**
* Gravity Perks // GP Populate Anything // Automatically Check Checkboxes
* http://gravitywiz.com/documentation/gravity-forms-populate-anything
*
* Instructions:
* 1. Install our free Custom Javascript for Gravity Forms plugin.
* Download the plugin here: https://gravitywiz.com/gravity-forms-custom-javascript/
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
*. 3. This snippet is meant to be a starting point. You will need to update the selectors accordingly
*/
@claygriffiths
claygriffiths / gf-surrogate-control-header.php
Created August 26, 2021 03:45
Gravity Forms: Add Surrogate-Control header if Gravity Form is present on page
<?php
/**
* Set Surrogate-Control header on pages with Gravity Forms to prevent Varnish from caching.
*
* This requires Varnish to be configured to utilize Surrogate-Control when present.
*
* See the follow material for more details:
* * https://developer.fastly.com/reference/http-headers/Surrogate-Control/
* * https://book.varnish-software.com/4.0/chapters/VCL_Basics.html#vcl-backend-response
*/