P
P
PRIZRAKeee2018-05-25 13:09:46
WordPress
PRIZRAKeee, 2018-05-25 13:09:46

How to change total order value in woocommerce?

Hello. The task is as follows: you need to change the final price in the cart on the site under the Wordpress management system with the Woocommerce plugin. I need this to create a basket of additional services on the page with its own cost. So that when you click on the desired checkbox in the cart, the amount I need is added to the final price (for example, 100 rubles). I have an idea how to send data ajax, but I don’t know what I need to write in the function.php file. Tell me please. On the Internet, I found that you need to use woocommerce_calculate_totals - action and woocommerce_calculated_total - filter. But I don't know how to connect

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PRIZRAKeee, 2018-05-28
@PRIZRAKeeee

Found what should help me. I'm leaving this here in case anyone needs it. The code is written in functions.php

//Изменяем подитог
add_filter( 'woocommerce_cart_subtotal', 'filter_woocommerce_cart_subtotal', 10, 3 ); 
function filter_woocommerce_cart_subtotal( $cart_subtotal, $compound, $instance ) { 
  $cart_subtotal = 10000;
    return $cart_subtotal; 
}; 

//Изменяем итог
add_filter( 'woocommerce_cart_total', 'filter_woocommerce_cart_total', 10, 3 ); 
function filter_woocommerce_cart_total( $cart_total, $compound, $instance ) { 
  $cart_total = 9999;
    return $cart_total; 
}; 

//Изменяем цену при подтверждении заказа
function filter_woocommerce_order_amount_total ( $array , $int , $int ) {
  $total_price = filter_woocommerce_cart_total();
  $subtotal_price = filter_woocommerce_cart_subtotal();
  $array = $total_price  + $subtotal_price;
    return $array; 
}; 
add_filter ( 'woocommerce_order_amount_total' , 'filter_woocommerce_order_amount_total' , 10 , 3 );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question