Displaying Coupon Code Messages in a Popup

115 views Asked by At

I am trying to display the WooCommerce Coupon messages ("Coupon code applied Successfully" & "Coupon Code does not Exist") in a popup via the plugin Popups for WooCommerce: Add to Cart, Checkout & More Pro paid version. Even though it is a paid plugin, I am getting no support.

Their documentation states any alert can be shown via the following:

You can use the [ttt_pnwc_get_message] shortcode to get dynamic messages from any filter you wish. e.g.

[ttt_pnwc_get_message filter="wc_add_to_cart_message_html"]

Any help would be much appreciated.

add_filter('woocommerce_coupon_error', 'coupon_error_message_change', 10, 3);

function coupon_error_message_change($err, $err_code, $parm) {
    switch ($err_code) {
        case 105:
            /* translators: %s: coupon code */
            $err = sprintf(__('Coupon "%s" does not exist!', 'woocommerce'), $parm->get_code());

            // Using the message in a popup
            $dynamic_message = esc_html($err);
            
            // Display the dynamic message in the popup using the shortcode
            echo do_shortcode("[ttt_pnwc_get_message message='$dynamic_message']");
            break;
    }
    return $err;
}
0

There are 0 answers