wc-donation / wc-donation-platform

Donation Platform for WooCommerce unleashes the power of WooCommerce for your online fundraising, crowdfunding & crowdsponsoring
https://www.wc-donation.com/
GNU General Public License v2.0
41 stars 10 forks source link

Hi, Can we set min & max donation amount on Per Product (campaign) Basis ? #9

Closed procontentxyz closed 2 years ago

procontentxyz commented 2 years ago

I have a use case, Where I need to set min & max donation amount per product (campaign) basis.

Currently your software provide it using global setting.

kindly address my use case.

jonas-hoebenreich commented 2 years ago

This feature is not currently provided. With the filter woocommerce_add_cart_item_data you can implement it yourself relatively easily. Just make sure to set the meta key 'wcdp_donation_amount' to your desired amount. Best, Jonas

procontentxyz commented 2 years ago

Suppose I have two products product A and product B,

I want to limit minimum donation amount to 100 in product A,

And minimum donation amount 300 in product B.

How can I do this using your filters that you have provided me in last answer can you guide please

Any tutorial or documentation page for this

jonas-hoebenreich commented 2 years ago

I'm a bit busy at the moment, so I can't write any individual code for you for the time being. What exactly are you failing at with the filter? (programming in php, how filter work, which values have to be set etc.)

procontentxyz commented 2 years ago

i have a 5 products on my site.

i have set minimum donation amount to be: 200 for : 3 of 5 products.

i want to set minimum donation amount to be 500 for remaining 2 products.

how to set minimum OR maximum donation amount per product basis, not globally.

pelase guide big brother.

jonas-hoebenreich commented 2 years ago

Haven't tried it, but based on this it shouldn't be too hard to implement it:

//filter cart item data, this data is used to update the product price later
add_filter( 'woocommerce_add_cart_item_data', function($cart_item_data, $product_id, $variation_id, $quantity) {
  if ($product_id == 123 && $cart_item_data['wcdp_donation_amount'] < 200) {
  //update amount
    $cart_item_data['wcdp_donation_amount'] = 200;
  }
  return cart_item_data;
}, 10, 4 );
procontentxyz commented 2 years ago

Could i set 'wcdp_donation_amount' meta using custom fields in product edit page?

Would it effect/override global setting?

jonas-hoebenreich commented 2 years ago

I have a feeling that you have never bothered to try to understand what the filter is doing. There is no product metadata stored here, but meta data from the Cart object.

The plugin checks if the specified donation amount is within the min/max range and stores it in the cart meta data. You can use the filter to alter the amount.

procontentxyz commented 2 years ago

Okk... Actually i am not a developer, i just try things

If its come as per need, i feel good