Hooks before and after adding to cart

Question

I want to limit the purchase of a product to N amount per day.

I have found these 3 hooks:

add_filter('woocommerce_add_to_cart_validation', 'filter_add_to_cart_validation', 10, 3);
add_filter('woocommerce_add_to_cart_quantity', 'filter_add_to_cart_validation', 10, 3);
add_action('woocommerce_add_to_cart', 'action_woocommerce_add_to_cart', 10, 6);

Should I just have all the logic in woocommerce_add_to_cart?

Check that the product in the cart doesn’t contain more than N minus whatever he already bought and delete or reduce the quantity accordingly?

Or should I separate stuff into each hook?

  • woocommerce_add_to_cart_validation to check if he can buy more.
  • woocommerce_add_to_cart_quantity to check he’s not adding more than N minus what he’s already bought today.
  • woocommerce_add_to_cart in this case would be just to double check?

I’m not sure what the pros and cons are on each case.

0
Daviid 8 months 2020-11-25T14:10:22-05:00 0 Answers 13 views 0

Leave an answer

Browse
Browse