• Resolved db7777777

    (@db7777777)


    Hello,
    Is it possible to always show the message that appears when a coupon is automatically applied? Right now, the message just shows up once (on whatever page you’re on) when you fulfill the requirements of that particular coupon.

    Thanks

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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?

    Thread Starter db7777777

    (@db7777777)

    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 );
        }
    }
    
    
    Thread Starter db7777777

    (@db7777777)

    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 ?> )

    Thread Starter db7777777

    (@db7777777)

    Great, thanks

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘How to always show automatically applied message’ is closed to new replies.