In woocommerce, we can add a discount to any order using Coupons feature (fixed amount, percent amount…).
Is it possible to add discount amount to any order programmatically where the discount amount can be any amount?
Any help will be appreciated.
The following function will allow you to make a fixed discount of any amount or a percentage discount. The order need to exist (to be saved before).
The function code (For Woocommerce versions 3.2+):
Code goes in function.php file of your active child theme (active theme). Tested and works.
USAGE Examples:
1) Fixed discount of
$12
(with a dynamic$order_id
):2) Percentage discount of
5%
(with a dynamic$order_id
):