Skip to content

Instantly share code, notes, and snippets.

View jetsloth's full-sized avatar

JetSloth jetsloth

View GitHub Profile
@jetsloth
jetsloth / wc-toggle-gfpa-collapsible.html
Created July 29, 2021 09:38
Toggle the WooCommerce elements (subtotal, total, quantity and add to cart) based on whether the last Collapsible Section is open or not. For use with WooCommerce Gravity Forms Product Addons and Collapsible Sections. The code below can be added to a HTML field in your form.
<script type="text/javascript">
(function($){
function toggleAddToCart( $form, show ) {
if ( typeof $form === 'undefined' || !$form.length ) {
return;
}
if ( show !== true ) {
show = false;
@jetsloth
jetsloth / gf-image-choices-field-example.html
Created March 13, 2017 09:51
Example markup of Image Choices with a normal field
<li id="field_x" class="gfield image-choices-field image-choices-use-images image-choices-show-labels image-choices-layout-horizontal ">
<label class="gfield_label">Field Label</label>
<div class="ginput_container ginput_container_radio">
<ul class="gfield_radio" id="input_x">
<li class="gchoice_x image-choices-choice">
<input name="input_x" type="radio" value="Choice Value" id="choice_x">
<label for="choice_x" id="label_x">
<span class="image-choices-choice-image-wrap" style="background-image:url(path/to/your/image)">
<img src="path/to/your/image" alt="Choice Label" class="image-choices-choice-image">
</span>
@jetsloth
jetsloth / gform_format_option_label.html
Last active June 10, 2021 00:43
Using gform_format_option_label together with Image Choices
<script type="text/javascript">
window.gform_format_option_label_original = window.gform_format_option_label;
window.gform_format_option_label = function(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId, index) {
// Update any of the variables to format, Eg;
// priceLabel = "";
return window.gform_format_option_label_original(fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId, index);
};
</script>
@jetsloth
jetsloth / gfic_choice_price_filter.html
Created June 5, 2021 00:57
Using JetSloth's gfic_choice_price filter to hide the price label in option fields
<script type="text/javascript">
window.jetsloth_add_filter('gfic_choice_price', function(priceLabel, selectedPrice, price, formId, fieldId, index){
return '';
});
</script>
@jetsloth
jetsloth / gform_set_post_meta_to_image_choices_urls.php
Last active May 25, 2021 01:53
Set the post meta field to selected image choices URL
<?php
add_filter( 'gform_post_data', 'gform_set_post_meta_to_image_choices_urls', 10, 3 );
function gform_set_post_meta_to_image_choices_urls( $post_data, $form, $entry ) {
foreach( $form['fields'] as $field ) {
$value = RGFormsModel::get_lead_field_value( $entry, $field );
if ( $field->type != 'post_custom_field' || !property_exists($field, 'postCustomFieldName') || empty($field->postCustomFieldName) || !property_exists($field, 'imageChoices_enableImages') || empty($field->imageChoices_enableImages) || !isset($post_data['post_custom_fields'][$field->postCustomFieldName]) ) {
// if it's not a custom field, doesn't use image choices, or no custom field name configured, skip
@jetsloth
jetsloth / gpecf_image_choices_custom_order_sumary_markup.php
Last active May 7, 2021 04:06
Gravity Perks eCommerce Fields Order Summary markup customised to include Image Choices display
<?php
add_filter( 'gpecf_order_sumary_markup', 'get_custom_order_summary_markup', 10, 6 );
function get_custom_order_summary_markup( $markup, $order, $form, $entry, $order_summary, $labels ) {
ob_start();
$form_id = rgar($form, "id");
?>
<table class="gpecf-order-summary" cellspacing="0" width="100%" style="<?php gp_ecommerce_fields()->style( '.order-summary' ); ?>">
<thead>
<tr>
@jetsloth
jetsloth / gppa_input_image_choices.php
Created October 27, 2020 22:34
Filter Gravity Wiz Populate Anything to add Image Choices from post featured image
<?php
add_filter( "gppa_input_choices", "gppa_populate_featured_image_choices", 100, 3 );
function gppa_populate_featured_image_choices( $choices, $field, $objects ) {
if ( ! property_exists($field, 'imageChoices_enableImages') || ! $field->imageChoices_enableImages ) {
return $choices;
}
$i = 0;
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500;700&display=swap');
/*To get the produc options fields working, you need to add a product field. */
/*However we don't want to show that in this example so lets hide it with CSS.*/
.hidden {
display: none;
visibility: hidden;
pointer-events: none;
}
/*Dark field lables*/
.top_label label.gfield_label {
@jetsloth
jetsloth / clean.css
Created March 2, 2021 22:52
Image Choices Clean Style Demo
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500;700&display=swap');
/*To get the produc options fields working, you need to add a product field. */
/*However we don't want to show that in this example so lets hide it with CSS.*/
.hidden {
display: none;
visibility: hidden;
pointer-events: none;
}
/*Background Wrapper*/
.gform_wrapper {
@jetsloth
jetsloth / add_colors_to_taxonomy_choices.php
Created August 15, 2020 01:55
Add color choices to field dynamically populated by the Gravity Forms + Custom Post Types plugin, where colors are set as the text of each taxonomy term
<?php
function add_colors_to_taxonomy_choices( $form ) {
global $gf_cpt_addon;
if ( empty($gf_cpt_addon) ) {
return $form;
}
foreach( $form['fields'] as &$field ) {
$taxonomy = $gf_cpt_addon->get_field_taxonomy( $field );
$colorPickerEnabled = ( isset($field['colorPicker_enableColors']) && !empty($field['colorPicker_enableColors']) );