Woocommerce how to change product total and quantity?

Woocommerce how to change product total and quantity.

I have created a section in backend where admin can add multiple quantities and there price.I have showed the quantities and there related price on product detail page as radio button. Now when user will select any quantity then price will be added according to selected quantity.This is quantity view on product detail page.

Read More
Qty  Price
1     $10
2     $20
3     $25
4     $30

if user will select the quantity 2 then on cart page i need to update quantity 2 and price total $20. Then again if user will selected qty 4 then in cart qty should be 6 and price should be $45.I am trying to doing it with this hook.But it is not changing the product price total.

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

function add_custom_price( $cart_object ) 
{
    global $woocommerce;
    $custom_price = $_POST["custom_prc"];

    foreach ( $cart_object->cart_contents as $key => $value ) 
    {
        $value['data']->price = $custom_price;
    }
}

Related posts

Leave a Reply