Nick Shaw

WooCommerce hide Klarna payment method if order total is under £35

Add this to the functions.php to hide Klarna payment method if the order total is under £35

//hide klarna if order total is under £35
add_filter( 'woocommerce_available_payment_gateways', 'rudr_turn_off_cod' );
function rudr_turn_off_cod( $available_gateways ) {	
	if( is_admin() ) {
		return $available_gateways;
	}	
	// STEP 1: Get order/cart total
	if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page		
		$order_id = wc_get_order_id_by_order_key( $_GET[ 'key' ] );
		$order = wc_get_order( $order_id );
		$order_total = $order->get_total();		
	} else { // Cart/Checkout page
		$order_total = WC()->cart->total;
	}	
	// STEP 2: Disable payment gateway if order/cart total is less than 35
	if ( $order_total < 35 ) {
		unset( $available_gateways[ 'klarna_payments' ] ); // unset klarna
	}
	return $available_gateways;
}
Exit mobile version