I am trying to update the price of the product based on user input on the product page.

add_action( 'woocommerce_before_calculate_totals', 'extra_price_add_custom_price', 9999, 1 );
function extra_price_add_custom_price( $cart ) {
    if ( is_admin() && !defined('DOING_AJAX') )

    foreach ( $cart->get_cart() as $cart_item ) {
            echo $cart_item['data']->price; // this gives the price that i want but

        if( isset($cart_item['custom_data']['new_price']) ){
            $cart_item['data']->set_price( floatval($cart_item['custom_data']['new_price']) ); // here price is not updated 

I found a filterwoocommerce_product_variation_get_price in some other plugin if I disable that plugin then my custom input value came.

i can not disable that plugin.

I want to know how woocommerce_product_variation_get_price and 'woocommerce_before_calculate_totals' are related to each other any why they override each other.

Thank You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.