I want to update cart subtotal in WooCommerce.

How can add action for modifying subtotal in WooCommerce?

I have tried to by this code, but is not working. I would like to multiply by 12 the cart subtotal and to display this calculation on cart page.

Here is my code:

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $total) {

    foreach ( $total->cart_contents as $key => $value ) {

        $modifiedtotal = $total->subtotal * 12; 
        // --------------------------------
        //how can get subtotal with multiply by 12 and it should be show on cart page.
    }
}

Read more here: Updating cart subtotal in WooCommerce


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: