{"id":301,"date":"2020-01-18T13:15:00","date_gmt":"2020-01-18T13:15:00","guid":{"rendered":"https:\/\/creativefruitbowl.com\/bytesized\/?p=301"},"modified":"2025-01-18T13:15:58","modified_gmt":"2025-01-18T13:15:58","slug":"automatically-apply-woocommerce-coupons-based-on-cart-quantity","status":"publish","type":"post","link":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/","title":{"rendered":"Automatically apply WooCommerce coupons based on cart quantity"},"content":{"rendered":"\n<p>Whilst working on the <a href=\"http:\/\/www.hildon.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">brand new Hildon website<\/a> I encountered an issue with WooCommerce coupons.<\/p>\n\n\n\n<p>You can&#8217;t&nbsp;create quantity-based coupons out of the box and whilst this functionality is available through plugins such as <em><a href=\"https:\/\/www.woothemes.com\/products\/dynamic-pricing\/\" target=\"_blank\" rel=\"noopener noreferrer\">Dynamic Pricing<\/a><\/em>, I&#8217;m a cheap-skate who doesn&#8217;t&nbsp;want to pay for plugins when I can do something&nbsp;for free &#8211;&nbsp;<em>plus programmatically&nbsp;creating\/amending coupons allows for greater control<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The principle<\/h2>\n\n\n\n<p>In case you&#8217;re unaware, Hildon produce some of the purest Natural Mineral Water in the UK&nbsp;and you can find bottles of Hildon in some of the finest establishments and restaurants around&nbsp;the&nbsp;World. They sell&nbsp;their bottles of Natural Mineral Water in cases and that is how quantities are measured online.<\/p>\n\n\n\n<p>Hildon only have two products &#8211; <em>Delightfully Still Natural Mineral Water<\/em> and <em>Gently Sparkling Natural Mineral Water<\/em> but there are up to 19 variations of those products.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A generous offer<\/h3>\n\n\n\n<p>Hildon like to reward their customers and they have a fantastic offer whereby if you order six or more cases of Natural Mineral Water, you get a 5% discount applied to your basket. If you order 12 or more cases, this offer increases to 10% off.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">In practice<\/h2>\n\n\n\n<p>As mentioned already, discount-based coupons are not available in WooCommerce out of the box.&nbsp;<strong><em>Fear not<\/em> &#8211; we can&nbsp;fix this issue quite easily.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Firstly&nbsp;&#8211; Create a WooCommerce coupon:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to WordPress and create a new coupon;<\/li>\n\n\n\n<li>Add a title for the coupon &#8211;&nbsp;<em>this is important as it will be referenced in code;<\/em><\/li>\n\n\n\n<li>You can now set up the rest of the coupon as you normally would &#8211;&nbsp;<em>i.e. Discount type, Discount amount etc; and finally<\/em><\/li>\n\n\n\n<li><strong>Don&#8217;t&nbsp;set <\/strong>any<strong> &#8220;Usage restrictions&#8221;&nbsp;<\/strong>or<strong>&nbsp;&#8220;Usage limits&#8221;&nbsp;<\/strong>for the coupon as they&#8217;ll likely be ignored by our code.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Secondly &#8211; Check for individual use coupons:<\/h3>\n\n\n\n<p>I have created a function that checks whether or not a coupon set to &#8220;Individual use&#8221; is currently applied to the customer cart. It simply returns <code>true<\/code> if an individual use coupon is applied and a <code>false<\/code>&nbsp;if not. We&#8217;ll use this function in upcoming code.<\/p>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/mangopearuk\/f8a4c6fc60c99eac3081#file-hildon_is_individual_coupon_applied-php\" target=\"_blank\" rel=\"noopener noreferrer\">You can grab this code from my Gist<\/a>.&nbsp;<em>You&#8217;ll probably want to rename the function to something more meaningful to your theme or plugin.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Thirdly &#8211; Set our conditions and apply coupons:<\/h3>\n\n\n\n<p><a href=\"https:\/\/gist.github.com\/mangopearuk\/f8a4c6fc60c99eac3081\" target=\"_blank\" rel=\"noopener noreferrer\">Grab the gist for our second function<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Hook the function:<\/h4>\n\n\n\n<p>You&#8217;ll need to create a function that you can hook in to <code>wp_head<\/code>. We only want the code to run on the cart and checkout pages though &#8211;&nbsp;I&#8217;d recommend using the <code>is_cart()<\/code> and <code>is_checkout()<\/code>&nbsp;conditionals that ship with WooCommerce.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Check for individual use coupons:<\/h4>\n\n\n\n<p>I have then set up an additional conditional statement to check whether or not an &#8220;Individual use&#8221; coupon is currently applied to the cart &#8211; if it is, we don&#8217;t to apply the 5% or 10% discounts. A simple check using the <code>hildon_is_individual_coupon_applied()<\/code> function is all that&#8217;s required here.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Custom conditions for coupon use:<\/h4>\n\n\n\n<p>After this, you&#8217;ll need to set up the conditions in which you wish the coupon(s) to be applied. In my code sample you can see that we have two coupons (5% discount and 10% discount) which are applied under certain circumstances.<\/p>\n\n\n\n<p>My code example works as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>If cart contains&nbsp;five or less&nbsp;units<\/em>&nbsp;(cases of Natural Mineral Water for Hildon) &#8211;<br>remove both coupons;<\/li>\n\n\n\n<li><em>If cart contains between 6 and 11 cases<\/em> &#8211;<br>apply the 5% discount and remove the 10% discount (only if applied); or<\/li>\n\n\n\n<li><em>If cart contains 12 or more cases<\/em> &#8211;<br>remove the 5% discount (if applied) and add the 10% discount.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Worth noting:<\/h4>\n\n\n\n<p>I have referenced the coupon names in variables so that if they change I only need update one location and not several.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The perfect solution?<\/h2>\n\n\n\n<p>I make no claim that this is the perfect solution for discount-based coupons in WooCommerce but it does have its advantages. It&#8217;s worked for our needs and has performed pretty well since the site has launched.<\/p>\n\n\n\n<p>Have you got a better solution? <a href=\"https:\/\/twitter.com\/MangopearUK\" target=\"_blank\" rel=\"noopener noreferrer\">Tweet us your ideas<\/a> or comment on this post.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code samples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Individual use coupon check:<\/h3>\n\n\n\n<pre class=\"wp-block-cedaro-code line-numbers\"><code class=\"language-php\">&lt;?php\n\n\t\/**\n\t * Automatically apply coupons for bulk discounts\n\t *\n\t * hildon_is_individual_coupon_applied()\n\t * \t\t[a]\tGet global class for woocommerce\n\t * \t\t[b]\tGet all Woo coupons that are set to individual use\n\t * \t\t[c]\tLoop through the coupons from [b]\n\t * \t\t[d]\tGet the title for each coupon\n\t * \t\t[e]\tFind out whether this coupon is currently applied in cart\n\t * \t\t\t[f]\tIf coupon is applied, return true\n\t * \t\t\t[g]\tIf coupon is not applied, return false\n\t *\/\n\t\n\tfunction hildon_is_individual_coupon_applied() {\n\t\tglobal \t$woocommerce; \/\/ [a]\n\t\t\n\n\t\t$coupon_args = array(\n\t\t\t'posts_per_page'\t=> -1,\n\t\t\t'orderby'\t\t\t=> 'title',\n\t\t\t'order'\t\t\t\t=> 'asc',\n\t\t\t'post_type'\t\t\t=> 'shop_coupon',\n\t\t\t'post_status'\t\t=> 'publish',\n\t\t\t'meta_key'\t\t\t=> 'individual_use',\n\t\t\t'meta_value'\t\t=> 'yes',\n\t\t);\n\t\t\n\n\t\t$coupons = get_posts($coupon_args); \/\/ [b]\n\t\t\n\n\t\tforeach ($coupons as $coupon) : \/\/ [c]\n\t\t\t$coupon_title = get_the_title($coupon); \/\/ [d]\n\t\t\t\n\t\t\tif ($woocommerce->cart->has_discount($coupon_title)) : return true; \/\/ [e][f]\n\t\t\telse : return false; \/\/ [e][g]\n\t\t\tendif;\n\t\tendforeach;\n\t}\n\n?><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Coupon conditions code:<\/h3>\n\n\n\n<pre class=\"wp-block-cedaro-code line-numbers\"><code class=\"language-php\">&lt;?php\n\n\t\/**\n\t * Automatically apply coupons for bulk discounts\n\t *\/\n\n\tfunction hildon_bulk_discount_coupons() {\n\t\tglobal \t$woocommerce; \/\/ [a]\n\t\t\n\n\t\tif (is_cart() || is_checkout()) :\n\t\t\tif (hildon_is_individual_coupon_applied() != true) :\n\t\t\t\t$coupon_five_percent = '5% discount'; \/\/ [b]\n\t\t\t\t$coupon_ten_percent  = '10% discount'; \/\/ [b]\n\t\t\t\t$cart_contents_count = $woocommerce->cart->cart_contents_count; \/\/ Get cart contents\n\t\t\t\t\n\n\t\t\t\t\/**\n\t\t\t\t * Check quantities and add coupons if valid\n\t\t\t\t *\n\t\t\t\t * [1]\tIf cart has 5 or less items\n\t\t\t\t * \t\t[a]\tRemove 5% coupon\n\t\t\t\t * \t\t[b]\tRemove 10% coupon\n\t\t\t\t *\n\t\t\t\t * [2]\tIf cart has between 6 and 11 items\n\t\t\t\t * \t\t[a]\tIf 5% coupon is applied, do nothing\n\t\t\t\t * \t\t[b]\tIf 10% coupon is applied\n\t\t\t\t * \t\t\t[i]\t\tApply 5% coupon\n\t\t\t\t * \t\t\t[ii]\tRemove 10% coupon\n\t\t\t\t * \t\t[c]\tIf neither coupon is applied\n\t\t\t\t * \t\t\t[i]\t\tAdd 5% coupon\n\t\t\t\t *\n\t\t\t\t * [3]\tIf cart has 12 or more items\n\t\t\t\t * \t\t[a]\tIf 5% coupon is applied\n\t\t\t\t * \t\t\t[i]\t\tRemove 5% coupon\n\t\t\t\t * \t\t\t[ii]\tApply 10% coupon\n\t\t\t\t * \t\t[b]\tIf 10% coupon is applied, do nothing\n\t\t\t\t * \t\t[c]\tIf neither coupon is applied\n\t\t\t\t * \t\t\t[i]\t\tAdd 10% coupon\n\t\t\t\t *\/\n\t\t\t\t\n\t\t\t\tif ($cart_contents_count &lt;= 5) : \/\/ [1]\n\t\t\t\t\tif ($woocommerce->cart->has_discount($coupon_five_percent)) : $woocommerce->cart->remove_coupon($coupon_five_percent); endif; \/\/ [1][a]\n\t\t\t\t\tif ($woocommerce->cart->has_discount($coupon_ten_percent)) :  $woocommerce->cart->remove_coupon($coupon_ten_percent); endif; \/\/ [1][b]\n\t\t\t\t\n\n\t\t\t\telseif ($cart_contents_count >= 6 &amp;&amp; $cart_contents_count &lt;= 11) : \/\/ [2]\n\t\t\t\t\tif ($woocommerce->cart->has_discount($coupon_five_percent)) : \/\/ [2][a]\n\t\t\t\t\t\t\/\/ do nothing();\n\t\t\t\t\t\n\t\t\t\t\telseif ($woocommerce->cart->has_discount($coupon_ten_percent)) : \/\/ [2][b]\n\t\t\t\t\t\t$woocommerce->cart->add_discount($coupon_five_percent); \/\/ [2][b][i]\n\t\t\t\t\t\t$woocommerce->cart->remove_coupon($coupon_ten_percent); \/\/ [2][b][ii]\n\t\t\t\t\telse : \/\/ [2][c]\n\t\t\t\t\t\t$woocommerce->cart->add_discount($coupon_five_percent); \/\/ [2][c][i]\n\t\t\t\t\tendif;\n\t\t\t\t\n\n\t\t\t\telse : \/\/ [3]\n\t\t\t\t\tif ($woocommerce->cart->has_discount($coupon_five_percent)) : \/\/ [3][a]\n\t\t\t\t\t\t$woocommerce->cart->remove_coupon($coupon_five_percent); \/\/ [3][a][i]\n\t\t\t\t\t\t$woocommerce->cart->add_discount($coupon_ten_percent); \/\/ [3][a][ii]\n\t\t\t\t\t\n\t\t\t\t\telseif ($woocommerce->cart->has_discount($coupon_ten_percent)) : \/\/ [3][b]\n\t\t\t\t\t\t\/\/ do nothing();\n\t\t\t\t\telse : \/\/ [3][c]\n\t\t\t\t\t\t$woocommerce->cart->add_discount($coupon_ten_percent); \/\/ [3][c][i]\n\t\t\t\t\tendif;\n\t\t\t\tendif;\n\t\t\t\n\n\t\t\telse : \/\/ If individual coupons are applied, remove default coupons\n\t\t\t\tif     ($woocommerce->cart->has_discount($coupon_five_percent)) : $woocommerce->cart->remove_coupon($coupon_five_percent);\n\t\t\t\telseif ($woocommerce->cart->has_discount($coupon_ten_percent)) :  $woocommerce->cart->remove_coupon($coupon_ten_percent);\n\t\t\t\tendif;\n\t\t\tendif;\n\t\tendif;\n\t}\n\t\n\t\n\tadd_action('wp_head', 'hildon_bulk_discount_coupons');\n\t\n?><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Whilst working on the brand new Hildon website I encountered an issue with WooCommerce coupons. You can&#8217;t&nbsp;create quantity-based coupons out of the box and whilst this functionality is available through plugins such as Dynamic Pricing, I&#8217;m a cheap-skate who doesn&#8217;t&nbsp;want to pay for plugins when I can do something&nbsp;for free &#8211;&nbsp;plus programmatically&nbsp;creating\/amending coupons allows for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Automatically apply WooCommerce coupons based on cart quantity - Bytesized - Our bite sized development blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatically apply WooCommerce coupons based on cart quantity - Bytesized - Our bite sized development blog\" \/>\n<meta property=\"og:description\" content=\"Whilst working on the brand new Hildon website I encountered an issue with WooCommerce coupons. You can&#8217;t&nbsp;create quantity-based coupons out of the box and whilst this functionality is available through plugins such as Dynamic Pricing, I&#8217;m a cheap-skate who doesn&#8217;t&nbsp;want to pay for plugins when I can do something&nbsp;for free &#8211;&nbsp;plus programmatically&nbsp;creating\/amending coupons allows for [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/\" \/>\n<meta property=\"og:site_name\" content=\"Bytesized - Our bite sized development blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-18T13:15:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-18T13:15:58+00:00\" \/>\n<meta name=\"author\" content=\"Andi North\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andi North\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/\"},\"author\":{\"name\":\"Andi North\",\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/#\\\/schema\\\/person\\\/499c021ef98dbfe1b06642ad37d8eb38\"},\"headline\":\"Automatically apply WooCommerce coupons based on cart quantity\",\"datePublished\":\"2020-01-18T13:15:00+00:00\",\"dateModified\":\"2025-01-18T13:15:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/\"},\"wordCount\":705,\"commentCount\":0,\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/\",\"url\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/\",\"name\":\"Automatically apply WooCommerce coupons based on cart quantity - Bytesized - Our bite sized development blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/#website\"},\"datePublished\":\"2020-01-18T13:15:00+00:00\",\"dateModified\":\"2025-01-18T13:15:58+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/#\\\/schema\\\/person\\\/499c021ef98dbfe1b06642ad37d8eb38\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/2020\\\/01\\\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automatically apply WooCommerce coupons based on cart quantity\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/#website\",\"url\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/\",\"name\":\"Bytesized - Our bite sized development blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/#\\\/schema\\\/person\\\/499c021ef98dbfe1b06642ad37d8eb38\",\"name\":\"Andi North\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/13036c828735394e144e4ea4f720b7c9e1cb0b567ae6ab7265fb620aa273a495?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/13036c828735394e144e4ea4f720b7c9e1cb0b567ae6ab7265fb620aa273a495?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/13036c828735394e144e4ea4f720b7c9e1cb0b567ae6ab7265fb620aa273a495?s=96&d=mm&r=g\",\"caption\":\"Andi North\"},\"sameAs\":[\"https:\\\/\\\/creativefruitbowl.com\"],\"url\":\"https:\\\/\\\/creativefruitbowl.com\\\/bytesized\\\/author\\\/fruitytest\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automatically apply WooCommerce coupons based on cart quantity - Bytesized - Our bite sized development blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/","og_locale":"en_GB","og_type":"article","og_title":"Automatically apply WooCommerce coupons based on cart quantity - Bytesized - Our bite sized development blog","og_description":"Whilst working on the brand new Hildon website I encountered an issue with WooCommerce coupons. You can&#8217;t&nbsp;create quantity-based coupons out of the box and whilst this functionality is available through plugins such as Dynamic Pricing, I&#8217;m a cheap-skate who doesn&#8217;t&nbsp;want to pay for plugins when I can do something&nbsp;for free &#8211;&nbsp;plus programmatically&nbsp;creating\/amending coupons allows for [&hellip;]","og_url":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/","og_site_name":"Bytesized - Our bite sized development blog","article_published_time":"2020-01-18T13:15:00+00:00","article_modified_time":"2025-01-18T13:15:58+00:00","author":"Andi North","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andi North","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/#article","isPartOf":{"@id":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/"},"author":{"name":"Andi North","@id":"https:\/\/creativefruitbowl.com\/bytesized\/#\/schema\/person\/499c021ef98dbfe1b06642ad37d8eb38"},"headline":"Automatically apply WooCommerce coupons based on cart quantity","datePublished":"2020-01-18T13:15:00+00:00","dateModified":"2025-01-18T13:15:58+00:00","mainEntityOfPage":{"@id":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/"},"wordCount":705,"commentCount":0,"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/","url":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/","name":"Automatically apply WooCommerce coupons based on cart quantity - Bytesized - Our bite sized development blog","isPartOf":{"@id":"https:\/\/creativefruitbowl.com\/bytesized\/#website"},"datePublished":"2020-01-18T13:15:00+00:00","dateModified":"2025-01-18T13:15:58+00:00","author":{"@id":"https:\/\/creativefruitbowl.com\/bytesized\/#\/schema\/person\/499c021ef98dbfe1b06642ad37d8eb38"},"breadcrumb":{"@id":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/creativefruitbowl.com\/bytesized\/2020\/01\/automatically-apply-woocommerce-coupons-based-on-cart-quantity\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/creativefruitbowl.com\/bytesized\/"},{"@type":"ListItem","position":2,"name":"Automatically apply WooCommerce coupons based on cart quantity"}]},{"@type":"WebSite","@id":"https:\/\/creativefruitbowl.com\/bytesized\/#website","url":"https:\/\/creativefruitbowl.com\/bytesized\/","name":"Bytesized - Our bite sized development blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/creativefruitbowl.com\/bytesized\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/creativefruitbowl.com\/bytesized\/#\/schema\/person\/499c021ef98dbfe1b06642ad37d8eb38","name":"Andi North","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/13036c828735394e144e4ea4f720b7c9e1cb0b567ae6ab7265fb620aa273a495?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/13036c828735394e144e4ea4f720b7c9e1cb0b567ae6ab7265fb620aa273a495?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/13036c828735394e144e4ea4f720b7c9e1cb0b567ae6ab7265fb620aa273a495?s=96&d=mm&r=g","caption":"Andi North"},"sameAs":["https:\/\/creativefruitbowl.com"],"url":"https:\/\/creativefruitbowl.com\/bytesized\/author\/fruitytest\/"}]}},"_links":{"self":[{"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":0,"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"wp:attachment":[{"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/creativefruitbowl.com\/bytesized\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}