Closed 5 years ago.
- Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
- Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?
I am coding a wordpress plugin that will run on a multi-vendor woocommerce site. I have a list of discounts (in percentage) that applies to all the products categories I have on the woocommerce site stored on a separate database along with my wordpress database. And I wish to be giving some certain members (that have a certain ID) when checking out and on the cart page these discounts depending on the products (i.e the categories the products belong to) they have on the cart.
In a nutshell, this ID should work like woocommerce coupon just that this time around its been gotten and validated from an external database.
For example, I have product category x, y, z to have discounts of 2%, 3%, 4% respectively on the database. So if a user add products a, b, c to the cart and product a belong to category x, b => y and c => z.
This plugin displays an input field expecting the user to type his or her ID to get the discounts applicable to the products he or she has on the cart, so when ID is found, the plugin should apply 2% discount to product a, 3% to product b and 4% to product c and recalculate the subtotal.
And all these happens via Ajax, I have been able to output the form, use Ajax to validate the entered ID. I need help on how to get the categories of the products on the cart or checkout in order to fetch the discounts of these products from my database and the hook to use in applying the discount and recalculating the subtotal. Please I need help, thanks in advance.