php – Price change from the js table Woocommerce

I have created two additional fields to calculate the price. I now need to set this price in the cart.

This is the code that calculates the price.

jQuery(function ($) {

const priceList = (5, 10, 15, 20, 25, 30);

let numberFrom = 0
let numberTo = 0;
let number = 0;


$('select(name="from")').on("change", function(){
    let optionSelected = $("option:selected", this);

    numberFrom = optionSelected(0).index;

    if(numberFrom != 0 && numberTo != 0) {
        number = Math.abs(numberFrom - numberTo);
        $('.woocommerce-Price-amount.amount bdi').text(`${priceList(number).toFixed(2)}zł`);
    }
});

$('select(name="to")').on("change", function(){
    let optionSelected = $("option:selected", this);

    numberTo = optionSelected(0).index;

    if(numberFrom != 0 && numberTo != 0) {
        number = Math.abs(numberFrom - numberTo);
        $('.woocommerce-Price-amount.amount bdi').text(`${priceList(number).toFixed(2)}zł`);
    }
});


});

I need the price taken from the table to be set for the client. Use AJAX for this?