Home > Software engineering >  Display coupon message on another pages on woocommerce
Display coupon message on another pages on woocommerce

Time:01-27

I need to show coupon applied message in cart-empty.php, because i created a button that send to cart and applied a coupon to cart automatically but when cart is empty does not show any message.

I tried to add this code to cart-empty.php but does not work as expected.

<div >
    <?php wc_print_notices(); ?>
</div>

CodePudding user response:

Try adding this code to your cart-empty.php file:

$coupons = WC()->cart->get_applied_coupons();
if ( $coupons ) {
    wc_print_notice( 'Coupon ' . implode( ', ', $coupons ) . ' has been applied to your cart.', 'notice' );
}

This will check if any coupons have been applied to the cart and if so, will display a notice with the applied coupon codes.

  • Related