Discount added with $cart->add_fee() is reducing the Subscription Price
-
My ‘Buy Now’ Button goes to the Checkout page and automatically adds a subscription Product besides the target product. When the subscription product gets added, I’m also giving a 25% discount due to the Subscription product. The discount is being calculated based on Cart Total and supposed to be a one-time thing. The Subscription product shows 0.00 total because it has a 5-day trial period. But when I get the payment receipt I find that the price of the Subscription product is also reduced by 25% … This is not intended. The discount should have been only on Cart Total, it should not be affecting the Subscription product price … can anyone give me some direction on this?
Here is the discount code:
`
/**
*
* CART DISCOUNT FUNCTION
*
*/function discount_based_on_product( $cart ) {
$product_id = get_field(‘woocom_product_id’, ‘option’);
$product_cart_id = WC()->cart->generate_cart_id( $product_id );
$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );if ( $in_cart ) {
// Collecting Product ID from ACF
$discount_percent = get_field(‘woocom_order_bump_discount’, ‘option’);// Cart Total
$total = $cart->cart_contents_total;
// Discount Calculation
$discount = $total * $discount_percent * 0.01;
// Add the discount$cart->add_fee(__( $discount_percent . ‘% Discount’, ‘woocommerce’), -$discount );
}
}
add_action(‘woocommerce_cart_calculate_fees’, ‘discount_based_on_product’, 10, 1);
`
The page I need help with: [log in to see the link]
- The topic ‘Discount added with $cart->add_fee() is reducing the Subscription Price’ is closed to new replies.