How can i get coupon disount in mini cart woocommerce?

Viewed 513

I tried to call in the mini cart woocommerce_cart_totals() to get a coupon discount. But in mini cart it's not working. It's working only when I go to the cart page and refresh the page.

After this, discount in mini cart is working fine. But now I want to know, why it's not working in another page? And not working without cart page refresh?

<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
        <tr class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
            <th><?php wc_cart_totals_coupon_label( $coupon ); ?></th>
            <td data-title="<?php echo esc_attr( wc_cart_totals_coupon_label( $coupon, false ) ); ?>"><?php wc_cart_totals_coupon_html( $coupon ); ?></td>
        </tr>
    <?php endforeach; ?>

view image - mini cart screenshot

0 Answers
Related