In WooCommerce I'm trying to get the cart total when hooking into woocommerce_add_to_cart
. That works, but the cart total returned is the total prior to the last added item. I want the updated total, to be able to display a notice regarding shipping costs.
Any idea how to achieve this?
My current code:
function oppsalg_add_to_cart() {
global $woocommerce;
// Limit
$minimum_cart_total = 1000;
// Cart value (Not including the last added item)
$total = WC()->cart->subtotal;
// Comparison
if( $total < $minimum_cart_total ) {
// Display notice
wc_add_notice( sprintf( '<strong>Shipping is free above %s.</strong>'
.'<br />Your total is %s. Perhaps you would like to add more items?',
$minimum_cart_total,
$total ),
'notice' );
}
}
add_action('woocommerce_add_to_cart', 'oppsalg_add_to_cart');