Skip to content

Instantly share code, notes, and snippets.

@rickalday
rickalday / givewp-custom-field.php
Created February 28, 2023 16:40
Add custom field to only specific forms
<?php
add_action( 'give_fields_after_donation_amount', function( $collection, $formID ) {
// Only display for forms with the IDs "35" and "578";
$forms = array( 35, 578 );
if ( in_array( $formID, $forms ) ) {
$collection->append(
// Select field with options.
give_field( 'select', 'myConference' )
->options(
[ 'east', __( 'Eastern Conference' ) ],
@rickalday
rickalday / polylang-givewp-assets-url.php
Created February 16, 2023 19:54
WP MU Plugin: Polylang multidomain GiveWP assets URL
<?php
/**
* MU plugin.
*
* Plugin Name: Polylang GiveWP Cross Domain Assets URL
* Description: Fixes cross origin domain issues with GiveWP and Polylang
* Version: 1.0
* Author: Rick Alday
* Author URI: http://www.rickalday.com/
*/
@rickalday
rickalday / custom-field-export.php
Created January 24, 2023 00:55
Export custom fields
<?php
function export_option_givewp_field_api_fields() {
?>
<tr class="give-export-option-fields give-export-option-custom-field">
<td scope="row" class="row-title">
<label><?php esc_html_e( 'Custom Field Title:', 'give' ); ?></label>
</td>
<td class="give-field-wrap">
<div class="give-clearfix">
<?php
/**
* @param array $args - associate array of data to be sent to Salesforce. example: ["Field_Name" => "Value"]
* @param SalesforceOpportunityData $data - the original data object where you can access things like donationId. example: $data->donationId
* @return array
*/
function addGiveSalesforceDonationArgs(
$args,
\GiveSalesforce\Salesforce\DataTransferObjects\SalesforceOpportunityData $data
@rickalday
rickalday / give_add_complete_date_pdf_tag.php
Created October 19, 2022 23:38
PDF Complete Date Tag
<?php
function give_add_complete_date_pdf_tag( $template_content, $args ) {
//$completedate = $args['payment_meta']['_give_completed_date'];
$completedate = date_i18n( get_option( 'date_format' ), strtotime( $args['payment_meta']['_give_completed_date'] ) );
$template_content = str_replace( '{completedate}', $completedate, $template_content );
return $template_content;
}
@rickalday
rickalday / givewp_clean_post_cache.php
Created October 13, 2022 23:08
Clean WP's cache after a GiveWP donation is processed
<?php
function givewp_clean_post_cache( $donation_id ) {
clean_post_cache( $donation_id );
}
add_action( 'give_update_payment_status', 'givewp_clean_post_cache' );
@rickalday
rickalday / tranlate_recurring_level_text.php
Last active September 30, 2022 17:29
Translate recurring level text
<?php
function tranlate_recurring_level_text() { ?>
<script>
var Give_Recurring_Vars = window.Give_Recurring_Vars;
jQuery( document ).ready( function( $ ) {
var doc = $( document );
@rickalday
rickalday / givewp_default_sequoia_template_settings.php
Last active September 23, 2022 19:49
Adds some default Multi-Step form template values for foms created using Ninja Forms Post Creation plugin
<?php
// Adds some default Multi-Step form template values
// Craate the _give_sequoia_form_template_settings and _give_donation_levels meta keys in Ninja Forms
// with a value of array
add_filter( 'ninja_forms_create_post_meta_value', function( $meta_value, $post_type, $meta_key ){
if( 'give_forms' == $post_type && '_give_sequoia_form_template_settings' == $meta_key ){
$meta_value = array (
'visual_appearance' =>
@rickalday
rickalday / givewp-api-custom-fieds.php
Last active September 30, 2022 16:21
GiveWP API Custom Fields Example
<?php
/**
* This function adds a custom field using GiveWP Fields API
*/
add_action( 'give_fields_after_donation_amount', function( $group ) {
$group->append(
give_field( 'text', 'guestName' )
->showInReceipt()
->minLength(2)
@rickalday
rickalday / givewp-populate-from-url.php
Last active April 1, 2024 15:08
Auto populate form from URL
function give_populate_amount_name_email() {
?>
<script>
jQuery( document ).ready(function() {
( function( window, document, jQuery, undefined ) {
'use strict';
var giveCustom = {};
giveCustom.init = function() {