Woocommerce Create New Discount Function

In Woocommerce, we need to create a new custom discount function. Before we try to change this in an existing function and because of many woocommerce filters the discount.

So, now we would like to make some changes to the new discount functionality.

If customer Enter coupon code:

  • Check this coupon if applicable for this product.

  • Find the category of this product

    • If category A, then 10% discount
    • If category B, then a discount of 20%, etc.
  • Calculate the total discount

    • Show general discount on basket page, check page
    • Show the new total price (initial total price - total discount) on the checkout page of the cart page.
  • Update all order metadata (or the corresponding default meta in woocommerce by default, which corresponds to the total discount for the total amount, etc.)

  • Check if the prices sent to the payment gateway are the same and check the price in the order received

Please help solve this problem. If anyone can help us with any basic codes, we are very grateful.

And we already see this document https://docs.woocommerce.com/document/create-a-coupon-programatically/

In our situation, we create a default coupon for a woocommerce coupon, but our functionality is different, different discounts for the same coupon based on the category of goods .

Woocommerce key for calculating discount coupons

-1
source share

All Articles