Support » Plugin: WooCommerce » Discount added with $cart->add_fee() is reducing the Subscription Price

  • Resolved ahmedmusawir

    (@ahmedmusawir)


    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);
    `

    • This topic was modified 4 years, 8 months ago by ahmedmusawir.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @ahmedmusawir,

    I am very sorry about the wait on this reply! I checked your site and see the 0.00, and I did a test purchase but did not get the order receipt. You should see the order for woologin@woocommerce.com. If you can please do a re-send receipt under Order Actions so we can do a further check?

    Could you please share a copy of your site’s System Status? You can find it via **WooCommerce > Status**.
    Select “Get system report” and then “Copy for support”.  Once you’ve done that, paste it here in your response. That will give us an idea of what is on your site in terms of plugins and theme overrides to check your code against.

    Hi @ahmedmusawir,

    I am going to close this thread for now, however if you are still having the issue just reply to this and we will re-open it.

    If you have other issues please open a new thread and let us know!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Discount added with $cart->add_fee() is reducing the Subscription Price’ is closed to new replies.