I need set a discount manually without using coupons.
I have checked the Woocommerce source in Github and I see that it uses "set_discount_total" functions, but it does not work.
I have tried WC()->cart->set_discount_total(15)
and $order->set_discount_total(15);
but nothing.
This is my code:
<?php
function letsgo_order_total($order_id, $posted_data, $order) {
$order = wc_get_order( $order_id );
$order->set_discount_total(50);
}
add_action('woocommerce_checkout_order_processed','letsgo_order_total',10,3);
?>
Actually I have discovered a way to do it, it works but I do not like the code:
<?php
$cart_discount = 50;
$discount = (double)get_post_meta($order_id,'_cart_discount',true);
update_post_meta($order_id,'_cart_discount',$cart_discount + $discount);
?>