Skip to content

Instantly share code, notes, and snippets.

@rickalday
rickalday / givewp_authorizenet_payment_description.php
Created November 14, 2025 20:46
Send custom data to Authorize.net
<?php
add_filter(
'give_authorize_recurring_payment_description',
function($description, $purchase_data, $subscription){
\Give\Framework\PaymentGateways\Log\PaymentGatewayLog::success('Contents of the variables',
[
'Purchase Data' => $purchase_data,
]
);
@rickalday
rickalday / allow_editors_only_give_campaign_pages.php
Created November 7, 2025 23:01
Restrict Editor role to Give Campaing Pages only
<?php
/**
* Allow editors to edit/delete ONLY pages that have the give_campaign_id meta key.
*/
/**
* Map meta caps so editors may only edit/delete posts that have give_campaign_id.
*
* @param array $caps Mapped capabilities to return.
* @param string $cap Capability being checked.
@rickalday
rickalday / update-givewp-form-colors.php
Created October 29, 2025 23:18
Change GiveWP's primary and secondary form colors
<?php
// Remove the inline styles from the doantion receipt page
add_action('wp_print_scripts', function () {
wp_add_inline_script('givewp-donation-confirmation-receipt', 'document.addEventListener("DOMContentLoaded", function () {
// Run after a short delay to ensure UI is ready
setTimeout(() => {
const element = document.getElementById("root-givewp-donation-confirmation-receipt");
element.removeAttribute("style");
@rickalday
rickalday / givewp_year_dropdown.php
Created October 27, 2025 20:43
Create a year dropdown field in a GiveWP form
<?php
function getYears(): array
{
$startYear = 1970;
$currentYear = date('Y');
return range($startYear, $currentYear);
}
add_action('givewp_donation_form_schema', static function (Give\Framework\FieldsAPI\DonationForm $form) {
$field = Give\Framework\FieldsAPI\Select::make('grduation_year')
->options(...getYears())
@rickalday
rickalday / givewp_non_selectable.php
Created October 13, 2025 19:12
Make the first element of a GiveWP dropdown element non-selectable
<?php
add_action("givewp_donation_form_enqueue_scripts", function () {
?>
<script>
document.addEventListener("DOMContentLoaded", function () {
// Run after a short delay to ensure UI is ready
setTimeout(() => {
@rickalday
rickalday / log_givewp_payment_meta.php
Created September 18, 2025 17:17
Log GiveWP donation data in Donations -> Tools -> Logs.
<?php
/**
* Log donation data in Donations -> Tools -> Logs.
*
* @param int $payment_id The ID of the inserted payment.
* @param array $payment_data The payment data array, which includes payment_meta.
*/
function log_givewp_payment_meta( $payment_id, $payment_data ) {
@rickalday
rickalday / give_export_give_cs_base_amount.php
Created September 3, 2025 15:44
Add a checkbox to export the donation base amount in GiveWP donation history export
<?php
function give_export_give_cs_base_amount() {
?>
<tr class="give-export-option-fields give-export-option-custom-field">
<td scope="row" class="row-title">
<label><?php esc_html_e( 'Base amount:', 'give' ); ?></label>
</td>
<td class="give-field-wrap">
<div class="give-clearfix">
@rickalday
rickalday / company_or_name.php
Last active July 22, 2025 18:36
Add {company_or_name} tag for PDF Receipts.
<?php
/**
* Add {company_or_name} tag to GiveWP PDF Receipts using the give_pdf_compiled_template_content filter.
* Outputs the Company name if provided, otherwise outputs donor's full name.
*/
add_filter( 'give_pdf_compiled_template_content', function( $template_content, $args ) {
//var_dump("<pre>".print_r($args,true)."</pre>");
//
// Make sure payment ID is available.
$payment_id = ! empty( $args['donation_id'] ) ? absint( $args['donation_id'] ) : 0;
@rickalday
rickalday / givewp_authorize_payment_description.php
Last active September 24, 2025 22:45
Filter the payment description sent to Authorize.net
<?php
add_filter(
'give_authorize_recurring_payment_description',
function($description, $purchase_data, $subscription){
/** Uncomment this block to get the $purchase_data array listed in Donations -> Tools -> Logs
* \Give\Framework\PaymentGateways\Log\PaymentGatewayLog::success('Contents of the variables',
* [
* 'Purchase Data' => $purchase_data,
* 'Subscription' => $subscription,
@rickalday
rickalday / set_donation_frequency_from_url.php
Created July 18, 2025 16:48
Sets the donation frequency based on the url parameter. Eg. yoursite.com/?payment_type=monthly
<?php
add_action("givewp_donation_form_enqueue_scripts", function () {
?>
<script>
document.addEventListener("DOMContentLoaded", function () {
const validValues = ["one-time", "daily", "week", "month", "quarter", "year"];
const params = new URLSearchParams(window.parent.location.search);
const paymentType = params.get("payment_type");
if (!paymentType || !validValues.includes(paymentType)) return;