### Full Example of [wcdp_order_counter]
Source: https://www.wc-donation.com/documentation/usage/wcdp_order_counter-shortcode
Combines all available attributes for a comprehensive configuration.
```text
[wcdp_order_counter id="123" label="{ORDER_COUNT} supporters so far!" fallback="No supporters yet, be the first!" cheat="-2"]
```
--------------------------------
### Target a specific product with a hook
Source: https://www.wc-donation.com/documentation/development/wcdp-template-hook-reference
Example of using the wcdp_before_step_amount hook while filtering by a specific product ID.
```php
function my_addon_before_amount( $product_id, $context ) {
if ( 42 !== $product_id ) {
return;
}
echo '
This campaign ends June 30.
';
}
add_action( 'wcdp_before_step_amount', 'my_addon_before_amount', 10, 2 );
```
--------------------------------
### Practical Examples for Donation Campaigns
Source: https://www.wc-donation.com/documentation/woocommerce-tips/customizing-your-donation-campaigns-using-the-products-shortcode
Common configurations for featuring urgent campaigns, showing category-specific projects, or randomizing the display.
```text
[products ids="123, 456, 789" columns="3"]
```
```text
[products limit="4" columns="4" category="education" orderby="date" order="DESC"]
```
```text
[products limit="6" columns="3" orderby="rand"]
```
--------------------------------
### Numbered placeholders example
Source: https://www.wc-donation.com/documentation/usage/internationalization-localization-translation
Demonstrates how to use numbered placeholders to reorder sentence structure in translations.
```text
%1$s donated %2$s to %3$s
```
```text
%1$s hat %3$s %2$s gespendet
```
--------------------------------
### Inject content after donor details
Source: https://www.wc-donation.com/documentation/development/wcdp-template-hook-reference
Example of using the wcdp_after_donor_details hook to output custom HTML content.
```php
function my_addon_after_donor_details( $product_id, $context ) {
echo 'Custom field here
';
}
add_action( 'wcdp_after_donor_details', 'my_addon_after_donor_details', 10, 2 );
```
--------------------------------
### PHP Example for Reverse Fee Calculation
Source: https://www.wc-donation.com/documentation/development/how-to-use-a-custom-formula-to-calculate-the-donation-fee
Implementation of the reverse calculation formula using a fixed fee of 0.25 and a variable fee of 1.5%.
```php
add_filter( 'wcdp_fee_amount', function( $fee, $payment_method, $cart ) {
$transaction_amount = $cart->get_subtotal(); // donation subtotal before fees
$fixed_fee = 0.25;
$variable_fee = 0.015; // 1.5%
// Calculate the fee needed so the net amount equals the original
$gross_amount = ( $transaction_amount + $fixed_fee ) / ( 1 - $variable_fee );
$fee = $gross_amount - $transaction_amount;
return round( $fee, 2 ); // round to two decimal places
}, 10, 3 );
```
--------------------------------
### Implement Custom Donation Template Override
Source: https://www.wc-donation.com/documentation/development/overriding-templates-with-wc_get_template
An example of using the wc_get_template filter to conditionally swap a donation form template with a custom file located in a child theme.
```php
add_filter( 'wc_get_template', 'custom_donation_template_override', 10, 5 );
function custom_donation_template_override( $located, $template_name, $args, $template_path, $default_path ) {
// Check for the specific Donation Platform template
if ( 'wcdp_form_style_3.php' === $template_name ) {
// Define the path to your custom template within your child theme
$overridden_template = get_stylesheet_directory() . '/my-custom-donations/amount-input.php';
// Ensure the file exists before overriding
if ( file_exists( $overridden_template ) ) {
return $overridden_template;
}
}
return $located;
}
```
--------------------------------
### Redirect to Custom Thank You Page via template_redirect
Source: https://www.wc-donation.com/documentation/advanced/custom-thank-you-page
Use this script to redirect users to a specific URL when they reach the order-received page. Ensure you replace the example URL with your desired destination.
```php
add_action( 'template_redirect', function() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'https://example.com' );
exit;
}
});
```
--------------------------------
### Incorrect translation example
Source: https://www.wc-donation.com/documentation/usage/internationalization-localization-translation
An incorrect translation that removes the required placeholder, which will cause errors.
```text
Vielen Dank für deine Spende!
```
--------------------------------
### Donation Leaderboard Attributes
Source: https://www.wc-donation.com/documentation/usage/donation-leaderboard
Examples of various attributes used to customize the leaderboard display.
```text
[wcdp_leaderboard id="123"]
```
```text
[wcdp_leaderboard limit="5"]
```
```text
[wcdp_leaderboard orderby="total"]
```
```text
[wcdp_leaderboard style="2"]
```
```text
[wcdp_leaderboard split="5"]
```
```text
[wcdp_leaderboard split="10" button="Load more"]
```
```text
[wcdp_leaderboard fallback="Be the first to donate!"]
```
--------------------------------
### Basic Usage of [products] Shortcode
Source: https://www.wc-donation.com/documentation/woocommerce-tips/customizing-your-donation-campaigns-using-the-products-shortcode
Displays a default grid of the most recent donation projects.
```text
[products]
```
--------------------------------
### Controlling Layout and Limits
Source: https://www.wc-donation.com/documentation/woocommerce-tips/customizing-your-donation-campaigns-using-the-products-shortcode
Configure the number of projects displayed and the number of columns in the grid.
```text
[products limit="3" columns="3"]
```
--------------------------------
### Basic Usage of [wcdp_order_counter]
Source: https://www.wc-donation.com/documentation/usage/wcdp_order_counter-shortcode
Displays the order count for a product with a specific ID.
```text
[wcdp_order_counter id="123"]
```
--------------------------------
### Customize label for $50 donation
Source: https://www.wc-donation.com/documentation/advanced/display-custom-text-in-radio-button-selection-options
Example of changing the $50 donation label to include text indicating the number of entries.
```php
add_filter('wcdp_label_50', function($label) {
return '$50 (10 Entries)';
});
```
--------------------------------
### WCDP Action Hooks
Source: https://www.wc-donation.com/documentation/development/wcdp-template-hook-reference
List of available action hooks for the WCDP template layer. All hooks pass two arguments: $product_id (int) and $context (string).
```APIDOC
## Action Hooks
### Available Hooks
- **wcdp_before_donation_form**: Fires before any form style renders.
- **wcdp_after_donation_form**: Fires after any form style renders.
- **wcdp_before_step_amount**: Fires before the amount picker form element.
- **wcdp_after_step_amount**: Fires above the Next/Donate button, after the amount fields.
- **wcdp_before_donor_details**: Fires before billing/shipping fields render (not available for style 4).
- **wcdp_after_donor_details**: Fires after billing/shipping fields render (not available for style 4).
### Arguments
- **$product_id** (int): The ID of the product being donated to.
- **$context** (string): The location where the form is rendered ('shortcode' or 'product-page').
```
--------------------------------
### Automatically set donation product to out of stock
Source: https://www.wc-donation.com/documentation/advanced/automatically-close-donations-when-fundraising-goal-is-reached
Use this snippet to automatically mark a donation product as 'outofstock' when the revenue meets or exceeds the defined goal.
```php
add_action('wcdp_goal_product_status', function($revenue, $goal_db, $product_id) {
if ($revenue < $goal_db) return;
// Set the product status to "sold out"
$product = wc_get_product($product_id);
if (!$product) return;
$product->set_stock_status('outofstock');
$product->save();
}, 10, 3);
```
--------------------------------
### Add Custom WooCommerce Thank You Message
Source: https://www.wc-donation.com/documentation/integrations/how-to-add-custom-code-to-your-page-using-the-code-snippets-plugin
An example PHP snippet that hooks into the woocommerce_thankyou action to display a custom message after a donation or purchase.
```php
// Example custom code for WooCommerce add_action('woocommerce_thankyou', 'custom_thankyou_message'); function custom_thankyou_message() { echo 'Thank you for your donation! Your support is greatly appreciated.
'; }
```