I am adding a custom fee to the cart by hooking into the woocommerce_cart_calculate_fees
action like so:
add_action('woocommerce_cart_calculate_fees', function add_loyalty_discounts(WC_Cart $cart)
{
$cart->add_fee('Loyalty Discount', -intval($_GET['discount']));
});
The fee appears on the cart page but not persist onto the checkout and order pages.
I’ve tried using $cart->set_session()
but this had no effect.
2
Answers
I tested and it works fine with me on both cart and checkout page
There are some mistakes, and missing things in your code, try the following:
Code goes in function.php file of your child theme (or in a plugin). It should work now.
Related: