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){

            $cart_item['data']->set_price($custom_price);
        }

    }

}

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

Read more here: Pass variables through AJAX to woocommerce_before_calculate_totals


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: