Custom Woocommerce Function

I was wondering if anybody would be so kind as to help me write a woocommerce function.
I am by no means a coder so i really appreciate any help you can offer.

What i wish to achieve is for a function to calculate the quantity of items in cart and then change the total order price based on predefined values.

So for example all items are £2.50 … what i want is for the function to count the items and if 5 items are in the cart change the cart total to £10 … if 10 items are added change the cart total to £20.00.

I am aware of some discount plugins which may achieve something similar, but i don’t actually want to apply a discount, i would really prefer to change the total automatically and not display a discount.

Once again i greatly appreciate any help.

function calculate_cart_price(){
    global $woocommerce;
    $cart_total = 0;
    // Get cart total
    foreach ( $woocommerce->cart->get_cart() as $key => $values ) {
        $cart_total += $values['quantity'];
    // Calculate the order total based on the quantity
    if ($cart_total >= 1 && $cart_total <= 10) {
        $order_total = 50;
    } elseif ($cart_total >= 11 && $cart_total <= 20) {
        $order_total = 100;
    } elseif ($cart_total >= 21 && $cart_total <= 30) {
        $order_total = 150;
    // Set the order total
Sponsor our Newsletter | Privacy Policy | Terms of Service