{"id":127850,"date":"2022-05-24T21:13:56","date_gmt":"2022-05-24T20:13:56","guid":{"rendered":"https:\/\/discountsuiteforwp.com\/?p=127850"},"modified":"2024-02-06T13:17:50","modified_gmt":"2024-02-06T12:17:50","slug":"woocommerce-coupon-code","status":"publish","type":"post","link":"https:\/\/www.orionorigin.com\/woocommerce-coupon-code\/","title":{"rendered":"How to create coupon codes in WooCommerce natively or with PHP"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#how-to-create-a-woo-commerce-coupon-code-natively\">How to create a WooCommerce Coupon Code natively\u00a0<\/a><ul><li><a href=\"#creating-a-woo-commerce-coupon-code-that-will-apply-a-discount-on-a-specific-product\">Creating a WooCommerce Coupon Code that will apply a discount on a specific product<\/a><\/li><\/ul><\/li><li><a href=\"#how-to-create-a-woo-commerce-coupon-code-by-using-the-programming-language-php\">How to create a WooCommerce Coupon Code by using the programming language &#8211; PHP\u00a0<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">WooCommerce coupon codes, just like any coupon from any content management system (CMS)&nbsp; can help attract new customers and generate a lot of sales, as of 2020, almost 90% of consumers used coupons (Source: <a href=\"https:\/\/www.statista.com\/\" target=\"_blank\" rel=\"noopener\">Statista<\/a>). Therefore for every online store owner, coupons are of the utmost importance. Knowing when and how to use them can be just the push you need to own a million-dollar store.<\/span><\/p>\n\n\n\n<div class=\"wp-block-cover is-light orion-cta-style\" style=\"min-height:217px;aspect-ratio:unset;\"><span aria-hidden=\"true\" class=\"wp-block-cover__background has-background-dim-80 has-background-dim\" style=\"background-color:#5c54ff\"><\/span><img decoding=\"async\" class=\"wp-block-cover__image-background wp-image-157867\" alt=\"\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2023\/05\/5.png\" data-object-fit=\"cover\" title=\"\"><div class=\"wp-block-cover__inner-container is-layout-flow wp-block-cover-is-layout-flow\">\n<div id=\"wp-block-themeisle-blocks-advanced-columns-678cc482\" class=\"wp-block-themeisle-blocks-advanced-columns has-1-columns has-desktop-equal-layout has-tablet-equal-layout has-mobile-equal-layout has-vertical-bottom ticss-c00aadba has-dark-bg\"><div class=\"wp-block-themeisle-blocks-advanced-columns-overlay\"><\/div><div class=\"innerblocks-wrap\">\n<div id=\"wp-block-themeisle-blocks-advanced-column-4d412c51\" class=\"wp-block-themeisle-blocks-advanced-column\">\n<h4 id=\"wp-block-themeisle-blocks-advanced-heading-fb3c7a39\" class=\"wp-block-themeisle-blocks-advanced-heading wp-block-themeisle-blocks-advanced-heading-fb3c7a39\">&nbsp;Easily attract more customers and grow your business by using our Custom Product Designer for Woocommerce.<\/h4>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-fe48e5de wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-primary is-style-outline is-style-outline--1\"><a class=\"wp-block-button__link has-white-color has-text-color wp-element-button\" href=\"https:\/\/wordpress.org\/plugins\/woocommerce-products-designer\/?utm_source=google&amp;utm_medium=article&amp;utm_campaign=Ouidah+Free+Version&amp;utm_id=8106\" style=\"border-radius:0px\" target=\"_blank\" rel=\"noreferrer noopener\">Download now<\/a><\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-create-a-woo-commerce-coupon-code-natively\"><span style=\"font-size: 18pt\"><strong>How to create a WooCommerce Coupon Code natively&nbsp;<\/strong><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">WooCommerce makes it pretty easy to create and manage coupon codes. Coupons are a standard WooCommerce feature that allows store admins to generate a code that can be used by the customer to apply a discount on his order without using any external add-ons. The coupon could either be for applying a discount on a specific product on the entire cart.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-a-woo-commerce-coupon-code-that-will-apply-a-discount-on-a-specific-product\"><span style=\"font-size: 14pt\"><strong>Creating a WooCommerce Coupon Code that will apply a discount on a specific product<\/strong><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 1:<\/strong> In order to set up a percentage discount on products using coupons, kindly go to <\/span><b>Marketing &gt; Coupons<\/b><span style=\"font-weight: 400\"> from your store admin area. <img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-128030 size-full\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2022\/05\/image1.png\" alt=\"How to create WooCommerce coupon codes - Tutorial\" width=\"1999\" height=\"780\" title=\"\"><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 2: <\/strong>Click on the &#8216;<b>Add Coupon&#8217;<\/b> button to access the coupons creation page<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2022\/05\/image2.png\" alt=\"How to create WooCommerce coupon codes - Tutorial\" class=\"wp-image-128032\" title=\"\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 3: <\/strong><\/span>Enter your coupon code or click on<b> &#8216;Generate coupon code&#8217;<\/b> to generate a random code for you. Keep in mind that all coupon codes must be unique.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 4: <\/strong>Please select <\/span><b>Percentage discount<\/b><span style=\"font-weight: 400\"> as the <\/span><b>discount type.<\/b><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 5: <\/strong>Enter your percentage number in the coupon amount field.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 6: <\/strong>If you want to set an expiration date for the coupon, you can enter that date in the coupon expiry date field<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 7: <\/strong><\/span>Click on Usage restriction to configure the coupon conditions for the customer to get the discount:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2022\/05\/image3.png\" alt=\"How to create WooCommerce coupon codes - Tutorial\" class=\"wp-image-128034\" title=\"\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Minimum spend: is the minimum to be spent by the customer in the current order to be eligible for the discount.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Maximum spend: is the maximum to be spent by the customer in the current order to be eligible for the discount.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Individual use only: to enable or disable the coupon usage along with other coupons for the same order.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Exclude sale items: excludes products that are already on sale from the coupon application.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Products: this allows you to list all the products on which the coupons will apply once enabled.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Exclude products: allows you to list all the products on which the coupons will apply once enabled<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Product categories: allows you to list all the products on which the coupons will NOT apply once enabled<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Exclude categories: list of categories that will be excluded from the coupon application<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Allowed emails: customers billing emails or domains that should be able to use the coupon and get the discount applied<\/span><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><strong>Step 8: <\/strong>Click on Usage limits to configure the coupon conditions for the customer to get the discount:<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-128036 size-full\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2022\/05\/image4.png\" alt=\"How to create WooCommerce coupon codes - Tutorial\" width=\"1580\" height=\"448\" title=\"\">Usage limit per coupon: allows you to set the number of times the coupon can be used<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Limit usage to X items: this allows you to set a maximum number of products per coupon usage<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Usage limit per user: this allows you to set a maximum number of usage per customer. Each customer is identified by his billing email.<\/span><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Once you\u2019re done, click on the &#8216;<\/span><b>Publish&#8217;<\/b><span style=\"font-weight: 400\"> button to make your coupon live.<\/span><\/p>\n\n\n\n<div class=\"wp-block-cover is-light orion-cta-style\" style=\"min-height:217px;aspect-ratio:unset;\"><span aria-hidden=\"true\" class=\"wp-block-cover__background has-background-dim-80 has-background-dim\" style=\"background-color:#5c54ff\"><\/span><img decoding=\"async\" class=\"wp-block-cover__image-background wp-image-157867\" alt=\"\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2023\/05\/5.png\" data-object-fit=\"cover\" title=\"\"><div class=\"wp-block-cover__inner-container is-layout-flow wp-block-cover-is-layout-flow\">\n<div id=\"wp-block-themeisle-blocks-advanced-columns-678cc482\" class=\"wp-block-themeisle-blocks-advanced-columns has-1-columns has-desktop-equal-layout has-tablet-equal-layout has-mobile-equal-layout has-vertical-bottom ticss-c00aadba has-dark-bg\"><div class=\"wp-block-themeisle-blocks-advanced-columns-overlay\"><\/div><div class=\"innerblocks-wrap\">\n<div id=\"wp-block-themeisle-blocks-advanced-column-4d412c51\" class=\"wp-block-themeisle-blocks-advanced-column\">\n<h4 id=\"wp-block-themeisle-blocks-advanced-heading-fb3c7a39\" class=\"wp-block-themeisle-blocks-advanced-heading wp-block-themeisle-blocks-advanced-heading-fb3c7a39\">&nbsp;Easily attract more customers and grow your business by using our Custom Product Designer for Woocommerce.<\/h4>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-fe48e5de wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-primary is-style-outline is-style-outline--2\"><a class=\"wp-block-button__link has-white-color has-text-color wp-element-button\" href=\"https:\/\/wordpress.org\/plugins\/woocommerce-products-designer\/?utm_source=google&amp;utm_medium=article&amp;utm_campaign=Ouidah+Free+Version&amp;utm_id=8106\" style=\"border-radius:0px\" target=\"_blank\" rel=\"noreferrer noopener\">Download now<\/a><\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-a-woo-commerce-coupon-code-that-will-apply-a-discount-on-the-cart-total\"><span style=\"font-size: 14pt\"><strong>Creating a WooCommerce Coupon Code that will apply a discount on the cart total<\/strong><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">If you want the coupon to be applied on the entire cart instead of specific products, follow the above steps but, make sure the \u2018products list\u2019 to apply the discount on is empty.&nbsp;<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2022\/05\/image5.png\" alt=\"How to create WooCommerce coupon codes - Tutorial\" class=\"wp-image-128038\" title=\"\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">That way, instead of applying the discount on a specific set of products, the coupon will apply the discount to the entire cart.<\/span><\/p>\n\n\n\n<div class=\"wp-block-cover is-light orion-cta-style\" style=\"min-height:217px;aspect-ratio:unset;\"><span aria-hidden=\"true\" class=\"wp-block-cover__background has-background-dim-80 has-background-dim\" style=\"background-color:#5c54ff\"><\/span><img decoding=\"async\" class=\"wp-block-cover__image-background wp-image-157867\" alt=\"\" src=\"https:\/\/www.orionorigin.com\/wp-content\/uploads\/2023\/05\/5.png\" data-object-fit=\"cover\" title=\"\"><div class=\"wp-block-cover__inner-container is-layout-flow wp-block-cover-is-layout-flow\">\n<div id=\"wp-block-themeisle-blocks-advanced-columns-678cc482\" class=\"wp-block-themeisle-blocks-advanced-columns has-1-columns has-desktop-equal-layout has-tablet-equal-layout has-mobile-equal-layout has-vertical-bottom ticss-c00aadba has-dark-bg\"><div class=\"wp-block-themeisle-blocks-advanced-columns-overlay\"><\/div><div class=\"innerblocks-wrap\">\n<div id=\"wp-block-themeisle-blocks-advanced-column-4d412c51\" class=\"wp-block-themeisle-blocks-advanced-column\">\n<h4 id=\"wp-block-themeisle-blocks-advanced-heading-fb3c7a39\" class=\"wp-block-themeisle-blocks-advanced-heading wp-block-themeisle-blocks-advanced-heading-fb3c7a39\">&nbsp;Easily attract more customers and grow your business by using our Custom Product Designer for Woocommerce.<\/h4>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-fe48e5de wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-primary is-style-outline is-style-outline--3\"><a class=\"wp-block-button__link has-white-color has-text-color wp-element-button\" href=\"https:\/\/wordpress.org\/plugins\/woocommerce-products-designer\/?utm_source=google&amp;utm_medium=article&amp;utm_campaign=Ouidah+Free+Version&amp;utm_id=8106\" style=\"border-radius:0px\" target=\"_blank\" rel=\"noreferrer noopener\">Download now<\/a><\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-create-a-woo-commerce-coupon-code-by-using-the-programming-language-php\"><span style=\"font-weight: 400\"><span style=\"font-size: 18pt\"><strong>How to create a WooCommerce Coupon Code by using the programming language &#8211; PHP<\/strong><\/span>&nbsp;<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">As a WordPress developer, you can use the PHP programming language to create coupon codes for your Woocommerce store or for your clients that have Woocommerce stores, simply because WordPress and Woocommerce run on PHP. To do so, you can use the code below:&nbsp;<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Once you choose your coupon code you can enter it below\n$coupon_code = 'UNIQUECODE2';\n\n\/\/Then you can set the amount that is fixed if you're setting a fixed discount.&nbsp;\n\/\/If not, the number you set will be considered as a percentage.\n$amount = '10'; \/\/ Amount\n\n\/\/Choose your discount type among these: fixed_cart, percent, fixed_product, percent_product\n$discount_type = 'fixed_cart';\n\n\/\/Coupons are WordPress custom post types. So we can create them just like a regular custom post type\n$coupon = array(\n'post_title' =&gt; $coupon_code,\n'post_content' =&gt; '',\n'post_status' =&gt; 'publish',\n'post_author' =&gt; 1,\n'post_type' =&gt; 'shop_coupon' );\n\n$new_coupon_id = wp_insert_post( $coupon );\n\n\/\/We make sure the coupon has been created so we can update it's properties\nif ( $new_coupon_id ) {\n\n    update_post_meta( $new_coupon_id, 'discount_type', $discount_type );\n    update_post_meta( $new_coupon_id, 'coupon_amount', $amount );\n    update_post_meta( $new_coupon_id, 'individual_use', 'no' );\n    \n    \/\/The list of products to which the coupon should apply is an array of the product id numbers\n    update_post_meta( $new_coupon_id, 'product_ids', '' );\n    \n    \/\/The list of products to exclude from the coupon application is an array of the product id numbers\n    update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );\n    update_post_meta( $new_coupon_id, 'usage_limit', '' );\n    update_post_meta( $new_coupon_id, 'expiry_date', '' );\n    update_post_meta( $new_coupon_id, 'apply_before_tax', 'yes' );\n    update_post_meta( $new_coupon_id, 'free_shipping', 'no' );\n\n} else\n\necho \"The coupon creation failed....\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">There you have it, how to create your coupon codes natively with your WooCommerce or using PHP programming language. Other than using coupon codes, there are other ways of offering discounts to your customer and target audience in order to increase your sales, you can check <\/span><a href=\"https:\/\/www.orionorigin.com\/discount\/guide-for-woocommerce-dynamic-pricing\"><span style=\"font-weight: 400\">here<\/span><\/a><span style=\"font-weight: 400\"> for a guide about discount types and how to set them up.\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Drop your thoughts or questions in the comment section, we are more than happy to listen and help!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WooCommerce coupon codes, just like any coupon from any content management system (CMS)&nbsp; can help attract new customers and generate a lot of sales, as of 2020, almost 90% of consumers used coupons (Source: Statista). Therefore for every online store owner, coupons are of the utmost importance. Knowing when and how to use them can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":149363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[416],"tags":[],"class_list":["post-127850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-discount"],"acf":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/posts\/127850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/comments?post=127850"}],"version-history":[{"count":8,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/posts\/127850\/revisions"}],"predecessor-version":[{"id":162852,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/posts\/127850\/revisions\/162852"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/media\/149363"}],"wp:attachment":[{"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/media?parent=127850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/categories?post=127850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orionorigin.com\/service\/wp\/v2\/tags?post=127850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}