How to Create Referral Coupons in WooCommerce: Add Notice and Copy-Paste Coupon Code Functionality With Expiry date

Connect With Us In Our Social Media

Table of Contents

Post Intro

Are you looking to boost your WooCommerce sales and attract new customers? Referral coupons can be a powerful tool in your marketing arsenal. With WooCommerce, you can easily create referral coupons that come with a notice and convenient copy-paste functionality for the coupon code.

In this tutorial, we will walk you through the process of setting up referral coupons in WooCommerce. We will cover how to add a noticeable message on your product pages, informing customers about the referral coupon offer. Additionally, we will implement a copy-paste feature for the coupon code, making it simple for customers to share it with their friends and family.

By the end of this tutorial, you will have a clear understanding of how to create referral coupons, display a notice, and enable the copy-paste functionality for the coupon code in your WooCommerce store.

Let’s dive in and learn how to maximize the potential of referral coupons in WooCommerce!

Youtube Tutorial

Login To Access Code Snippet:

Post More Detail

Understanding the Code:

To create referral coupons with notice and copy-paste functionality in WooCommerce, we will be using a combination of custom code snippets and the Code Snippets plugin. The code snippets provided in this tutorial are meant to be added to the plugin for easy management and execution.

The code consists of several functions, each serving a specific purpose. Let’s break down how they work:

1. Adding the Custom Checkbox and Input Field:

The functions add_custom_product_checkbox and add_custom_product_input_field are responsible for adding a custom checkbox and input field to the WooCommerce product edit page, respectively. These allow you to enable referral coupons for specific products and set the discount amount.

2. Saving the Checkbox and Input Field Values:

The functions save_custom_product_checkbox and save_custom_product_input_field handle saving the values of the custom checkbox and input field when a product is saved or updated. The checkbox value is stored as post meta with the key enable_referral_coupon, while the input field value is stored with the key referral_coupon_discount.

3. Adding Custom CSS Styling:

The add_custom_css function adds custom CSS styles to change the appearance of the referral notice, coupon code, discount amount, and expiry date. You can modify these styles to match your website’s design.

4. Displaying the Referral Notice:

The display_single_product_notice function is responsible for displaying the referral notice on the single product page after the add to cart form. It checks if the “Enable Referral Coupon” checkbox is checked for the product and displays the notice accordingly.

5. Creating Referral Coupon Code Automatically:

The create_referral_coupon_code_automatically_after_purchase function is triggered on the “woocommerce_thankyou” action. It creates a referral coupon code automatically after a successful purchase. The function checks if any product in the order has the “Enable Referral Coupon” checkbox checked. If found, it generates a coupon code based on the customer’s billing first name and the discount amount set for the product. The coupon is then saved with the expiry date set to 30 days from the purchase date.

6. Copying the Coupon Code:

The copy_coupon_code_js function includes a JavaScript snippet that enables the copy-paste functionality for the coupon code. When the user clicks on the coupon code, it gets copied to their clipboard, and an alert is displayed confirming the successful copy.

Getting the Code Working on Your Website:

To get the referral coupon functionality working on your WooCommerce website, follow these steps:

Step 1: Install the Code Snippets Plugin:

Install and activate the Code Snippets plugin from the WordPress plugin repository. This plugin allows you to manage and execute custom code snippets easily.

Step 2: Add the Code Snippets:

Go to “Snippets” in your WordPress dashboard and click on “Add New.” Copy and paste each code snippet mentioned in this tutorial into separate snippets and save them.

Step 3: Activate the Snippets:

Activate all the snippets you created by checking the corresponding checkboxes next to each snippet and clicking “Save Changes.”

Step 4: Test the Functionality:

Go to your WooCommerce product edit page and check the “Enable Referral Coupon” checkbox. Set the referral coupon discount amount in the input field. Save or update the product. Now, visit the single product page and confirm that the referral notice is displayed correctly. Place a test order and check if a referral coupon code is generated automatically.

Congratulations! You have successfully implemented referral coupons with notice and copy-paste functionality in WooCommerce.

Note: Make sure to customize the CSS styles provided in the add_custom_css function to match your website’s design preferences.

Conclusion In summary

Summary:

  1. Referral coupons in WooCommerce offer a powerful way to boost sales and attract new customers.
  2. By implementing custom code snippets and using the Code Snippets plugin, you can easily enable referral coupons with notice and copy-paste functionality on your WooCommerce website.
  3. The code snippets allow you to add a custom checkbox and input field to enable referral coupons and set the discount amount for specific products.
  4. A referral notice is displayed on the single product page, informing customers about the available referral coupon offer.
  5. After a successful purchase, referral coupon codes are automatically generated based on the customer’s billing first name and the product’s discount amount. Customers can conveniently copy the coupon code with a simple click and share it with their friends and family.

Implementing referral coupons in your WooCommerce store can incentivize customers to make purchases and encourage them to refer others, leading to increased sales and customer engagement.

Search

Connect With Us In Our Social Media

S
U
B
S
C
R
I
B
E

Stay UpTo Date with Latest Post And news:

0
Would love your thoughts, please comment.x
()
x

Login To Access Code Snippet:

Stay UpTo Date with Latest Post And news: