AI Verified

Name

WooCommerce Show Coupon Code Used In Emails

About

This snippet looks at if there are any coupon codes used in the order.If there are, it fetches the coupon coupon type, name and the amount.If the coupon code type is a percentage based discount, a percentage symbol is appended to the amount.If the coupon code type is a fixed based discount, the currency symbol prefixes the amount.Any codes are then shown in a formatted table which has had CSS applied to make it match the rest of the tables shown in the email.Both the discount name and amount is shown beneath the main order details table.

Language

PHP

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

Simply copy the pre-coded solution to your active child theme’s functions.php or preferably the Code Snippets Plugin.

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://www.ecommercehints.com/woocommerce-show-coupon-code-used-in-emails

Codevault

ecommercehints

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://www.ecommercehints.com/

History

Last modified:

06/07/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WooCommerce Show Coupon Code Used In Emails

 
                    
1/**
2 * Snippet Name: WooCommerce Show Coupon Code Used In Emails
3 * Snippet Author: ecommercehints.com
4 */
5 
6add_action( 'woocommerce_email_after_order_table', 'ecommercehints_show_coupons_used_in_emails', 10, 4 );
7function ecommercehints_show_coupons_used_in_emails( $order, $sent_to_admin, $plain_text, $email ) {
8 if (count( $order->get_coupons() ) > 0 ) {
9 $html = '<div class="used-coupons">
10 <h2>Used coupons<h2>
11 <table class="td" cellspacing="0" cellpadding="6" border="1"><tr>
12 <th>Coupon Code</th>
13 <th>Coupon Amount</th>
14 </tr>';
15 
16 foreach( $order->get_coupons() as $item ){
17 $coupon_code = $item->get_code();
18 $coupon = new WC_Coupon($coupon_code);
19 $discount_type = $coupon->get_discount_type();
20 $coupon_amount = $coupon->get_amount();
21 
22 if ($discount_type == 'percent') {
23 $output = $coupon_amount . "%";
24 } else {
25 $output = wc_price($coupon_amount);
26 }
27 
28 $html .= '<tr>
29 <td>' . strtoupper($coupon_code) . '</td>
30 <td>' . $output . '</td>
31 </tr>';
32 }
33 $html .= '</table><br></div>';
34 
35 $css = '<style>
36 .used-coupons table {
37 width: 100%;
38 font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif;
39 color: #737373;
40 border: 1px solid #e4e4e4;
41 margin-bottom:8px;
42 }
43 .used-coupons table th, table.tracking-info td {
44 text-align: left;
45 border-top-width: 4px;
46 color: #737373;
47 border: 1px solid #e4e4e4;
48 padding: 12px;
49 }
50 .used-coupons table td {
51 text-align: left;
52 border-top-width: 4px;
53 color: #737373;
54 border: 1px solid #e4e4e4;
55 padding: 12px;
56 }
57 </style>';
58 
59 echo $css . $html;
60 }
61}

1

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

7

WooCommerce Show Number Of People Viewing Product

Added: 1 year ago

Last Updated: 1 month ago

We want to make this solution absolutely clear from the outset. This snippet does NOT generate the actual number of people viewing the product. It shows a randomly generated number in the range of two...

WooCommerce

AI Verified

1

WooCommerce Show Custom Content Between Short Description And Add To Cart

Added: 1 year ago

Last Updated: 2 months ago

In this guide, we show you how you can display custom content between the short description and add to cart button. Sure, you could just add additional content to the short description meta box, but h...

WooCommerce

AI Verified

0

Disable description/editor for Woocommerce products

Added: 1 year ago

Last Updated: 1 year ago

Disable the description/editor for Woocommerce products

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

7

WooCommerce Show Number Of People Viewing Product

Added: 1 year ago

Last Updated: 1 month ago

We want to make this solution absolutely clear from the outset. This snippet does NOT generate the actual number of people viewing the product. It shows a randomly generated number in the range of two...

WooCommerce

AI Verified

5

WooCommerce Show Number Of Units Sold On Product Page

Added: 1 year ago

Last Updated: 2 months ago

Showing the number of product units sold on the single product page is a great way to introduce Fear Of Missing Out (FOMO). You can highlight how many products are sold to let customers know a product...

WooCommerce

AI Verified

3

WooCommerce Add Content Under The Proceed To Checkout Button On The Cart Page

Added: 1 year ago

Last Updated: 2 months ago

How many times have you bought something online and seen trust symbols near the proceed to checkout button on the cart page? “30 Day Money Back Guarantee” or “Secure Checkout” are popular examples. By...