M
M
madc0de2016-10-25 02:22:47
WordPress
madc0de, 2016-10-25 02:22:47

Correct final price hook for WooCommerce?

Good day of the day.
In the class-wc-cart.php file, on line 1401+, there is a code that is included in the calculate_totals() function:

$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp ), $this ) );

This is the calculation of the final price of the goods that a person pays. I can change this code to my liking and everything works perfectly. But after each WC update, the code returns to its original form.
Therefore, I ask for help with a hook that I can place in my plugin or function.php file and after updating WC nothing will break for me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2016-10-25
@madc0de

The filter is built like this woocommerce_calculated_total :

// The following example is for adding a hook callback.
// define the woocommerce_calculated_total callback 
function filter_woocommerce_calculated_total( $round, $instance ) { 
    // make filter magic happen here... 
    return $round; 
};
// add the filter 
add_filter( 'woocommerce_calculated_total', 'filter_woocommerce_calculated_total', 10, 2 );

Here is an example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question