Answer the question
In order to leave comments, you need to log in
How to pass the total changed amount in the cart in woocommerce?
Hello! There is an online store on woocommerce
In the cart there is an arbitrary field for additional sales beds , depending on the increase of which the price increases
Now I need to put the price received in the total script when the order button is pressed into the $totalprice variable inside the woocommerce_before_calculate_totals hook , which is responsible for the final calculation of the amount. How to achieve this?
add_action('woocommerce_before_calculate_totals', 'set_custom_price');
function set_custom_price($cart_obj) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$getcart = WC()->cart->get_cart();
foreach ( $getcart as $cart_item_key => $cart_item ) {
$cart_item['data']->set_price( ( $totalprice ) );
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question