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