Developer guide

Print the donation form from PHP, override the templates, style the markup and work with the data both plugins store.

FreePro

Architecture

FreePro
NamespaceSiteryn\SiterynDonationsSiterynPro\SiterynDonations
Bootsiteryn_donations_loadedsiteryn_donations_pro_loaded, siteryn_donations_pro_features_loaded (licensed only)
Settings optionsiteryn_donations_settingssiteryn_donations_pro_settings
Admin pageadmin.php?page=siteryn-donationsAdds tabs to the same page
Public API versionPlugin::API_VERSION = 1.0Requires API 1.0

Pro is built only on Free's documented hooks and public methods: amounts, validation, the cart, the donation box, templates and the settings engine all come from Free. Everything that isn't listed here or in the Hooks reference is internal.

Functions

<?php siteryn_donations_form(); ?>          // the donation form (same as the shortcode)
<?php siteryn_donations_form( 123 ); ?>     // for donation product 123

siteryn_donations_is_donation_product( $product ); // bool
siteryn_donations();                               // the running Free Plugin, or null
siteryn_donations_pro();                           // the running Pro Plugin, or null
siteryn_donations_pro_campaign_progress( 123 );    // raised, goal, donors, percent, closed

Public methods include DonationWidget::render( $context, $product_id = 0 ), DonationCart::add_donation( $amount, $product_id = 0, $context = 'cart', $extra = array() ) (returns the cart item key or a WP_Error), DonationCart::remove_donation(), DonationCart::get_cart_donations(), Orders::get_donation_items( $order ), Orders::get_donation_total( $order ), the Amounts helpers (parse(), validate(), format(), get_fixed_amounts(), get_limits()) and, in Pro, Campaigns\Campaign::get( $product )->progress().

Templates

TemplatePluginShows
donation-widget.phpFreeThe donation box and the Donate page form
amount-picker.phpFreeThe amounts and the custom amount field
campaign-progress.phpProA campaign's progress bar
frequency-picker.phpProThe recurring choice
thank-you.phpProThe thank-you message (page and email)

Copy a file to your-theme/siteryn-donations/ (Pro's too). Keep the data-siteryn-donations-* attributes, the field names and the @version header: when your copy is older than the plugin's, store managers see "Siteryn Donations template files should be updated". The cart box and the Donate page render as a <form> that also works without JavaScript; on the checkout the box is a <div> inside WooCommerce's form.

Markup and CSS

.siteryn-donations-widget { --siteryn-donations-radius: 16px; }

Sending extra fields with a donation

Name an input siteryn_donations_extra[your_key] inside the box (print it on siteryn_donations_widget_before_actions) or a donation product's add to cart form. It arrives in the $extra argument of siteryn_donations_cart_item_data on the classic pages, the blocks and product pages alike. Sanitize and whitelist what you read. Pro's frequency choice works this way.

Assets

The siteryn-donations stylesheet and script load on the cart, checkout and donation product pages, and wherever the box renders. Load them elsewhere with add_filter( 'siteryn_donations_enqueue_assets', '__return_true' ). Pro's siteryn-donations-pro stylesheet follows Free's, and loads on the order received page.

Requests and endpoints

EndpointUsed by
?wc-ajax=siteryn_donations_updateThe box on classic pages and the shortcode (nonce siteryn_donations_update): add, update or remove
Store API extensionCartUpdate, namespace siteryn-donationsThe box on Cart and Checkout block pages
Form post to the current pageThe no-JavaScript fallback
wp_ajax_siteryn_donations_save_settingsSave Changes in the settings
admin_post_siteryn_donations_reset_settings / admin_post_siteryn_donations_pro_reset_settingsReset to Defaults
wp_ajax_siteryn_donations_pro_license_actionLicense activate and deactivate
wp_ajax_siteryn_donations_pro_recalculateRecalculate campaign totals
admin_post_siteryn_donations_pro_exportExport CSV

Admin actions require manage_woocommerce and a nonce; Pro's also require an active license (except license activation).

Data

WhereKeyHolds
Optionsiteryn_donations_settingsFree settings
Optionsiteryn_donations_product_id / siteryn_donations_page_idThe product and page created on activation
Product meta_siteryn_donation = yesThe Donation flag
Cart itemsiteryn_donationarray( 'amount' => '10', … )
Order item meta_siteryn_donation, _siteryn_donation_amountMarks a donation line and its amount
Option Prositeryn_donations_pro_settingsPro settings
Product meta Pro_siteryn_donations_pro_campaign, _siteryn_donations_pro_raised, _siteryn_donations_pro_donorsCampaign settings and running totals
Order meta Pro_siteryn_donations_pro_tally, _siteryn_donations_pro_totalWhat the order last added to each campaign
Order item meta Pro_siteryn_donations_recurring, _siteryn_donations_recurring_paidThe chosen frequency, and when the paid hook fired

Order data is read and written only through WooCommerce's own APIs, so it works with HPOS. Campaign totals change by differences only, so re-processing an order never counts it twice.

WPML and Polylang

wpml-config.xml declares the translatable text settings and copies the _siteryn_donation flag to translations. The Multilingual class (object_id(), matching_ids(), with_language(), order_language()…) is public for extensions; siteryn_donations_order_language changes the language of an order's emails.