Reputation: 655
I am trying desperately to get something that is simple. I know it's simple, I have done it many times before but it is not working and driving me insane.
I want the cart total in php for my woocommerce cart. so I can compare the value and determine if it is at a point where I initiate other functions.
this is what I have tried and in every case it returns either "0" or a string in which the cart value is again, 0.
string example:
<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>0.00</span>
the methods I have tried using are as follows, this is right in the woocommerce docs but they give no useful information:
$total = $woocommerce->cart->get_total();
$total_a = WC()->cart->get_total();
$total1 = $woocommerce->cart->get_total_ex_tax();
$total1_a = WC()->cart->get_total_ex_tax();
$total2 = $woocommerce->cart->get_cart_total();
$total2_a = WC()->cart->get_cart_total();
$total_testy = $woocommerce->cart->total();
from past experience some of these would just give me the total in an integer and away I go. now they give nothing but 0. can anyone see why this is not working?
Upvotes: 0
Views: 2472
Reputation: 655
the issue I ran into was the result of the hook location I was using. I was using a hook that fired before the cart total was calculated due to me wanting to edit product prices based off the cart total and manipulate them before calculating the total. by using the following wc hook:
add_action('woocommerce_cart_totals_before_order_total', 'my_function', 99 );
I was able to get the value of the cart total and make my price changes based off the result and injecting it into another function.
so there is a basic thing that caused me a lot of frustration, be cautious of hooks and where they trigger.
Upvotes: 1