In this update we have introduced AJAX cart coupon for offcanvas. That comes with a change for snippet “Get cart subtotal” that now needs to count with discounts and fees.
Replace its code with this:
function bt_get_cart_subtotal() {
// Ensure WooCommerce cart is initialized and not empty
if ( WC()->cart && ! WC()->cart->is_empty() ) {
$subtotal = WC()->cart->get_subtotal();
$discount_total = WC()->cart->get_discount_total();
$fee_total = 0;
// Calculate total fees if any
foreach ( WC()->cart->get_fees() as $fee ) {
$fee_total += $fee->amount;
}
// Calculate the total including fees and subtracting discounts
$total_with_fees_discounts = $subtotal + $fee_total - $discount_total;
// Format the final total
return wc_price( $total_with_fees_discounts );
}
// Return 0 formatted as currency if the cart is empty
return wc_price(0);
}
Offcanvas cart now available as a standalone
Due to its popularity, the offcanvas cart scripts have been extracted, allowing you to use them without the need for an addon plugin. Follow this tutorial.