Minimum & Maximum Donation Amount for a Specific Product

In this article, we will explain how users can configure these minimum and maximum donation amounts using the Donation Platform for WooCommerce (WCDP) and provide an example of how to modify these amounts per product using a filter. The plugin allows users to set store-wide minimum and maximum donation amounts. These amounts define the acceptable range for donation values for products within the WooCommerce store. The plugin utilizes filters to retrieve and apply these defined minimum and maximum amounts.

Modifying Minimum and Maximum Donation Amounts per Product

Users have the flexibility to modify the minimum and maximum donation amounts on a per-product basis using filters. The ‘wcdp_min_amount’ and ‘wcdp_max_amount’ filters can be used to adjust the minimum and maximum donation amounts for a specific product.

Example: Modifying Minimum Donation Amount

Here’s an example of how users can use the ‘wcdp_min_amount’ filter to change the minimum donation amount for a product with a specific product ID (e.g., product ID 91):

add_filter('wcdp_min_amount', function($amount, $product_id) {
    if ($product_id === 91) return 2; // Set the minimum donation amount to 2 for product ID 91
    return $amount; // Use the default minimum donation amount for other products
}, 10, 2);

In this example:

  • The ‘wcdp_min_amount’ filter is utilized to modify the minimum donation amount based on the product ID.
  • If the product ID is 91, the minimum donation amount is set to 2; otherwise, the default minimum donation amount is used.

Example: Modifying Maximum Donation Amount

Similarly, users can use the ‘wcdp_max_amount’ filter to change the maximum donation amount for a product with a specific product ID (e.g., product ID 91):

add_filter('wcdp_max_amount', function($amount, $product_id) {
    if ($product_id === 91) return 200; // Set the maximum donation amount to 200 for product ID 91
    return $amount; // Use the default maximum donation amount for other products
}, 10, 2);

In this example:

  • The ‘wcdp_max_amount’ filter is utilized to modify the maximum donation amount based on the product ID.
  • If the product ID is 91, the maximum donation amount is set to 200; otherwise, the default maximum donation amount is used.

By employing these filters, WooCommerce store owners can tailor the donation amounts to suit specific products, ensuring a customized donation experience for their customers.