I want to get cart contents total in woocommerce within woocommerce_before_calculate_totals
hook. So to achieve this I am using this code
add_action( 'woocommerce_before_calculate_totals', 'get_before_calculate_totals', 10 );
function get_before_calculate_totals( $cart_object ) {
global $woocommerce;
echo WC()->cart->get_cart_contents_total(); //returns 0
}
But it returns 0 every time. So can someone tell me how to get cart total without currency within woocommerce_before_calculate_totals
hook?
Any help and suggestion would be really appreciable.
2
Answers
/* change this line
WC()->cart->get_cart_contents_total()
with
$woocommerce->cart->get_cart_total()
because you have defined global $woocommerce; for woocommerce object */
As
woocommerce_before_calculate_totals
is used before any totals calculations, use instead the following that makes items subtotals calculations: