Add A Discount Programmatically To An Order In Woocommerce 3.2+
Answer : The only available feature to make a discount programmatically for an Order , is tricking the Fee API . For info, this trick is not recommended by woocommerce, but used by many people as there is not a discount feature in Woocommerce outside Coupons. 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+) : /** * Add a discount to an Orders programmatically * (Using the FEE API - A negative fee) * * @since 3.2.0 * @param int $order_id The order ID. Required. * @param string $title The label name for the discount. Required. * @param mixed $amount Fixed amount (float) or percentage based on the subtotal. Required. * @param string $tax_class The tax Class. '' by default. Optional. */ function wc_order_add_discount( $order_id, $title, $amount, $tax_class = '' ) { $order = wc_ge...