add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 10, 1); function add_custom_price( $cart_obj ) { // This is necessary for WC 3.0+ if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; foreach ( $cart_obj->get_cart() as $key => $value ) { $value['data']->set_price( 40 ); } }
if I set $ value ['data'] → set_price (40), it works fine, but:
foreach ( $cart_obj->get_cart() as $key => $value ) { $price = 50; $value['data']->set_price( $price ); }
Doretto
source share