• Hello,

    My website has a custom fee added at checkout using the add_fee() function from the WC_Cart class. The problem is that PayPal does not see this fee and calculates a higher amount.

    For example, if I have a product priced at 100$ and a custom fee of -10$, PayPal requests 100$ instead of 90$. Other payment processors, such as Stripe, calculate correctly.

    Thanks!

Viewing 1 replies (of 1 total)
  • Plugin Support Krystian from Syde

    (@inpsydekrystian)

    Hello @dani249

    We would need a sample of your code to investigate further, but using negative fees might seem intuitive within the site’s interface but can cause compatibility issues, especially with platforms like PayPal.

    A recommended and seamless method is to use WooCommerce’s built-in coupon system and apply the coupon programmatically based on specific conditions.

    Here’s a clear example:

    function generate_and_apply_programmatic_discount() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    
    $coupon_code = 'PROGRAMMATIC_DISCOUNT';
    
    // Check if coupon exists
    $coupon = new WC_Coupon($coupon_code);
    if (!$coupon->get_id()) {
    // If coupon doesn't exist, create it
    $coupon_data = array(
    'code' => $coupon_code,
    'amount' => '15',
    'discount_type' => 'fixed_cart',
    'description' => 'Programmatic discount applied when certain conditions are met.'
    );
    $new_coupon = new WC_Coupon();
    $new_coupon->read_manual_coupon($coupon_code, $coupon_data);
    $new_coupon->save();
    }
    
    // Check the cart's total
    if( WC()->cart->subtotal > 50 && ! WC()->cart->has_discount( $coupon_code ) ) {
    WC()->cart->apply_coupon( $coupon_code );
    }
    }
    add_action( 'woocommerce_cart_loaded_from_session', 'generate_and_apply_programmatic_discount' );

    By following this approach, you’ll be aligning more closely with WooCommerce’s intended mechanisms for providing discounts. This can help ensure greater compatibility with various payment gateways and offer a consistent user experience.

    I hope this helps.

    Kind regards,
    Krystian

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.