Plugin Author
Soft79
(@josk79)
Hi, if you enter a description for the coupon, it will be displayed in the cart totals block.
To display it somewhere else, you need to apply a hook. Where do you want it displayed and on what pages?
Hi,
We entered a description for each of our coupons and it already displays the name of the coupon in the cart total like we want.
We were hoping to have this boxed message that says “Discount applied: [coupon name]” on each individual product page, along with the cart and checkout page…so that it doesn’t only show up once (basically, we want customers to see a permanent message that their coupon was automatically applied, instead of it showing up once and then disappearing).
Thanks
Plugin Author
Soft79
(@josk79)
Try this snippet in functions.php:
<?php
add_action( 'woocommerce_before_cart', 'soft79_display_coupon_message' );
add_action( 'woocommerce_before_checkout', 'soft79_display_coupon_message' );
add_action( 'woocommerce_before_main_content', 'soft79_display_coupon_message' );
function soft79_display_coupon_message() {
foreach( WC()->cart->applied_coupons as $coupon_code ) {
$coupon = new WC_Coupon( $coupon_code );
$coupon_excerpt = $coupon->get_description();
$msg = sprintf(
__("Discount applied: %s", 'woocommerce-jos-autocoupon'),
__( empty( $coupon_excerpt ) ? $coupon_code : $coupon_excerpt, 'woocommerce-jos-autocoupon')
);
wc_print_notice( $msg );
}
}
Hi,
We tried adding this snippet and it broke the website…is it supposed to be at a certain location/area in the functions.php file?
Plugin Author
Soft79
(@josk79)
Paste at the end. Don’t include <?php if that’s already somewhere else (and not followed by ?> )