I am looking for a Woocommerce hook that will help change the discount percentage based on 2 different product category restrictions when a particular coupon is applied.
For example, if a customer adds a specific coupon, I will like:
- If the basket item belongs to product category A, it will give a 10% discount on this product.
- if he is in product category B, he will give a 20% discount on this product
- Update final price
Is there any hook that may be available to achieve this? Any action hook or filter hook available?
This is my code:
add_filter( 'woocommerce_get_discounted_price', 'apply_coupon', 10); function apply_coupon($price) { global $woocommerce; $product=$woocommerce->cart->product; if(has_term( 'duplex-blinds', 'A' ,$product->id)){ get_product_cart_price; 10% DISCOUNT } if(has_term( 'duplex-blinds', 'A' ,$product->id)){ 20% DISCOUNT } upadte total_discunt_incart($new_discount); upadte new_price_in_cart($new_price); upadte new_price_in_checkout($new_price); return $price; }
The important thing is that I need to change the total price of the goods , the total redemption value , the total discount price and the discount price to send to Paypal.
There are a lot of hooks in my store, so if you consider that the calculation of the default coupon in trading will be incorrect. And I noticed that the price of the basket in the basket goes correctly based on the user value of the product, but it does not update from the original basket amount, so the total price remains unchanged.
But on the discount page, the discount price is calculated based on the original price of the product, and not the commodity price of the product, so the discount goes wrong and it is also not minimized from the total price ...
Manik source share