Good afternoon, I need to pass variables using AJAX to the next function in the “functions.php” of my template.

add_action( 'woocommerce_before_calculate_totals', 'woocommerce_pj_update_price', 99 );

function woocommerce_pj_update_price() {

    $custom_price = 1000; // This will be your custom price  
    $target_product_id = 518; //Product ID

    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

        if($cart_item['data']->get_id() == $target_product_id){




I am grateful to anyone who can help me, giving me a small example.

Read more here: Pass variables through AJAX to woocommerce_before_calculate_totals


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: