December 2, 2022

How To Restrict Coupon For The First Order in WooCommerce

Table of Contents

Restrict a Coupon for the First Order in WooCommerce
Image from jcomp on Freepik

Restrict Coupon for the first order only

By using this code snippet, you will be able to restrict coupon for the first order in WooCommerce. You do not need any paid or free plugin to achieve this task. Coupon is one of the great way to attract new customers by providing discounts on purchases. You can increase your revenue by providing discounts and offers to your customer.

How to Restrict Coupon for the First Order In WooCommerce

If you have already created the coupon for the first order, this code snippet will help you to restrict coupon discount for the very first order on Woo-Commerce.
What does this code mean?
  • Guest users cannot use the discount coupons. To use coupons, users have to register/login into their account to apply for discount coupons.
  • Coupons will not apply if the user has previous orders in their respective accounts.
  • You can adjust the code if you want to restrict any specific coupon for the first order.

Note:

I strongly suggest taking a backup of your latest version of your functions.php file before making any changes. Make sure you have access to the server. I suggest you try and test on your staging or local development rather than applying code directly to the production or live environment.

You need to copy this code snippet and paste at the bottom of your functions.php file located at the child theme folder of your website. Path should look like this: public_html/wp-content/themes/your-child-theme
add_action('woocommerce_applied_coupon', 'apply_coupon_restriction');
function apply_coupon_restriction( ) {


    global $woocommerce;
    $remove_coupon = false;

    
    if ( is_user_logged_in() ) {  
  
        // Check if the customer has bought before
        $has_bought_before = wc_get_customer_order_count( get_current_user_id() ) >= 1 ? true : false;

        // Coupon been applied, but customer has bought before
        if ( $has_bought_before ) {
            $remove_coupon = true;
        } 

        /*
		If you want to check a specific Coupon to be removed

		$coupon_id = '12345';

	    if(in_array($coupon_id, $woocommerce->cart->get_applied_coupons())){
	        // set $remove_coupon = true; and remove applied coupon
	    }
	    */
    }
    else {
        wc_clear_notices();
        WC()->cart->remove_coupons();
        wc_add_notice( __( 'Please Login or Register your account to apply coupon', 'woocommerce' ), "error" ) ;
        return  false;
    }

    // When true
    if ( $remove_coupon ) {

        // Remove coupon
        WC()->cart->remove_coupons();

        // Show message
        wc_clear_notices();
        wc_add_notice( __( 'Coupon code is only applicable to the First Order Only', 'woocommerce' ), "error" ) ;
        return false;
      
    }

}

Coupon Restriction Using Paid Plugins for First Order

There are paid plugins also available in the market to create, display and manage coupons. Some plugins offers special features such as Virtual Gift Cards, Store Credits, QR Code on Gift Cards to use them more easily and quickly.

How To Create A Coupon and Set Coupon Restrictions

By following this steps you will be able to create coupons for your customers. You will learn how to apply controls over the coupons such as usage restriction, minimum and maximum order value and many things.

Let us dive deep in to creating a coupon in WooCommerce and further we will learn how to restrict customer to use coupon for the first order only.

Step 1. Create a Coupon

To create a new coupon, Go to Marketing -> Coupons menu and click on Add coupon button. Check the below image.
Create a new coupon in WooCommerce

Step 2. Set Coupon Code and Discount Type

Here you can set type of discount you want to offer to your customers. Set coupon amount and coupon expiry date. Apply coupon settings as shown in below image.

  • Enter Coupon Code.
  • Enter Coupon Description.
    From General Tab, Select discount type. If you want to give a fixed discount amount (in this case $10), Select Fixed Cart Discount and set Coupon Amount 10.
  • Set Coupon expiry date to apply coupon validity.  
Apply Coupon Restriction in WooCommerce

Step 3. Coupon Restriction Based On Usage

 Set coupon usage restrictions as shown in below image.

  • You can set minimum and maximum spend to control coupon eligibility.
  • Allow or restrict customers to use multiple coupons on the same cart.
  • You can control if a coupon should apply to the items on sale or not.
  • Create coupons for products or categories.
  • Exclude products or categories for a coupon.
  • Allow coupons for specific users. Only users with mentioned email ids can apply coupons on their cart.
Apply Coupon Restriction in WooCommerce

Step 4. Usage Limit for a Coupon in WooCommerce

The Usage limit tab gives you control over the usage of the coupons by the customers.
  • If the Usage limit per coupon is set to 100, then only 100 coupons are available for the customers to use on their cart. Once all are used, coupons will be unavailable. 
  • If the Usage limit per user is set to 1, then a customer can use this coupon once.
How to Restrict Coupon for the first order

Once the coupon controls are set, Click on Publish button to save and enable coupons for the customers.

Facts About Discount Coupons

Customers loves a deal when they shop. They actively search for coupons online. 96% of the 1,300 respondents to CouponFollow’s survey stated they actively look for internet coupons before making purchases. Additionally, 51% of respondents admitted to researchers that they almost always look for an online coupon code before making an online purchase. Coupon increases conversions and can lower the cost of marketing.

Conclusion

We have explained how to restrict a coupon for the first order. If you are a beginner, we have explain you how to create a new coupon and how to apply certain controls to the coupon. Reach us if you have some queries.
Share it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright @ 2022

This site uses cookies to offer you a
better browsing experience.