{"id":216,"date":"2019-07-03T08:55:03","date_gmt":"2019-07-03T08:55:03","guid":{"rendered":"http:\/\/bossakov.eu\/wpdemo\/?page_id=216"},"modified":"2023-03-30T01:33:36","modified_gmt":"2023-03-30T01:33:36","slug":"discount-codes-example","status":"publish","type":"page","link":"https:\/\/bossakov.eu\/wpdemo\/pvb-cf7-calculator-pro\/discount-codes-example\/","title":{"rendered":"Discount codes example"},"content":{"rendered":"<p>This is a very simple example of how you can implement discount codes managed in a separate Excel file on the server.<\/p>\n<p>Try these codes:<\/p>\n<p><strong>TESTPERCENT<\/strong> &#8211; percentage discount, 20%<br \/>\n<strong>TESTFIXED<\/strong> &#8211; fixed discount of $5<\/p>\n<p>You can download the Excel spreadsheet <a href=\"https:\/\/bossakov.eu\/wpdemo\/wp-content\/uploads\/2019\/07\/discounts.xlsx\">here<\/a>.<\/p>\n\n<div class=\"wpcf7 no-js\" id=\"wpcf7-f214-o1\" lang=\"en-US\" dir=\"ltr\" data-wpcf7-id=\"214\">\n<div class=\"screen-reader-response\"><p role=\"status\" aria-live=\"polite\" aria-atomic=\"true\"><\/p> <ul><\/ul><\/div>\n<form action=\"\/wpdemo\/wp-json\/wp\/v2\/pages\/216#wpcf7-f214-o1\" method=\"post\" class=\"wpcf7-form init\" aria-label=\"Contact form\" novalidate=\"novalidate\" data-status=\"init\">\n<fieldset class=\"hidden-fields-container\"><input type=\"hidden\" name=\"_wpcf7\" value=\"214\" \/><input type=\"hidden\" name=\"_wpcf7_version\" value=\"6.1.7\" \/><input type=\"hidden\" name=\"_wpcf7_locale\" value=\"en_US\" \/><input type=\"hidden\" name=\"_wpcf7_unit_tag\" value=\"wpcf7-f214-o1\" \/><input type=\"hidden\" name=\"_wpcf7_container_post\" value=\"0\" \/><input type=\"hidden\" name=\"_wpcf7_posted_data_hash\" value=\"\" \/><input type=\"hidden\" name=\"_wpcf7cf_hidden_group_fields\" value=\"[]\" \/><input type=\"hidden\" name=\"_wpcf7cf_hidden_groups\" value=\"[]\" \/><input type=\"hidden\" name=\"_wpcf7cf_visible_groups\" value=\"[]\" \/><input type=\"hidden\" name=\"_wpcf7cf_repeaters\" value=\"[]\" \/><input type=\"hidden\" name=\"_wpcf7cf_steps\" value=\"{}\" \/><input type=\"hidden\" name=\"_wpcf7cf_options\" value=\"{&quot;form_id&quot;:214,&quot;conditions&quot;:[],&quot;settings&quot;:{&quot;animation&quot;:&quot;yes&quot;,&quot;animation_intime&quot;:200,&quot;animation_outtime&quot;:200,&quot;conditions_ui&quot;:&quot;normal&quot;,&quot;notice_dismissed&quot;:true,&quot;repeater_remove_button&quot;:&quot;bottom&quot;,&quot;wpcf7cf_settings_saved&quot;:1}}\" \/>\n<\/fieldset>\n<p><label>Subtotal ($):<br \/>\n<span class=\"wpcf7-form-control-wrap\" data-name=\"subtotal\"><input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" value=\"1000\" type=\"text\" name=\"subtotal\" \/><\/span><\/label>\n<\/p>\n<p><label>Discount code:<br \/>\n<span class=\"wpcf7-form-control-wrap\" data-name=\"discount-code\"><input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" value=\"\" type=\"text\" name=\"discount-code\" \/><\/span><\/label>\n<\/p>\n<p><label>Second discount code:<br \/>\n<span class=\"wpcf7-form-control-wrap\" data-name=\"second-discount-code\"><input size=\"40\" maxlength=\"400\" class=\"wpcf7-form-control wpcf7-text\" aria-invalid=\"false\" value=\"\" type=\"text\" name=\"second-discount-code\" \/><\/span><\/label>\n<\/p>\n<p><input class=\"wpcf7-form-control wpcf7-calculate_button cf7-calculate_button\" type=\"button\" value=\"Calculate\" \/>\n<\/p>\n<div style=\"display:none\">\n\n<!-- Look up the discount code and match it to a number -->\n\t<p>[spreadsheet_reference raw_discount cf7-hide field:discount-code sheet:1 cells:A1-B10 \"http:\/\/bossakov.eu\/wpdemo\/wp-content\/uploads\/2019\/07\/discounts.xlsx\"]<br \/>\n[spreadsheet_reference raw_discount_2 cf7-hide field:second-discount-code sheet:1 cells:A1-B10 \"http:\/\/bossakov.eu\/wpdemo\/wp-content\/uploads\/2019\/07\/discounts.xlsx\"]\n\t<\/p><!-- We need to apply some behind-the-scenes number transformations to see if the discount is a fixed amount or a percentage. If the number is >= 1, then it is a fixed discount, otherwise we assume it is a percentage -->\n\n<!-- First, round down to the nearest integer -->\n\t<p><span class=\"wpcf7-form-control-wrap temp\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-calculation pvb-display-none cf7-calculation\" readonly=\"readonly\" aria-invalid=\"false\" value=\"0\" type=\"text\" name=\"temp\" \/><\/span><br \/>\n\n\t<\/p>\n\n<!-- Then, normalize to either 0 or 1 -->\n\t<p><br \/>\n\n\t<\/p>\n<\/div>\n\n<!-- Calculate discount -->\n<p><label>Discount: $ <\/label>\n<\/p>\n\n<!-- Calculate total -->\n<p><label>Total: $ <\/label>\n<\/p><input type=\"hidden\" name=\"_pvb_ajax_calc_nonce\" value=\"2bb8cd4581\"><div class=\"wpcf7-response-output\" aria-hidden=\"true\"><\/div>\n<\/form>\n<\/div>\n\n<h2>Source code for this form:<\/h2>\n<pre>&lt;label&gt;Subtotal ($):\n$ [text subtotal \"1000\"]&lt;\/label&gt;\n\n&lt;label&gt;Discount code:\n[text discount-code]&lt;\/label&gt;\n\n&lt;label&gt;Second discount code:\n[text second-discount-code]&lt;\/label&gt;\n\n[calculate_button calculate_button-1 \"Calculate\"]\n\n&lt;div style=\"display:none\"&gt;\n\n&lt;!-- Look up the discount code and match it to a number --&gt;\n[spreadsheet_reference raw_discount cf7-hide field:discount-code sheet:1 cells:A1-B10 \"https:\/\/bossakov.eu\/wpdemo\/wp-content\/uploads\/2019\/07\/discounts.xlsx\"]\n[spreadsheet_reference raw_discount_2 cf7-hide field:second-discount-code sheet:1 cells:A1-B10 \"https:\/\/bossakov.eu\/wpdemo\/wp-content\/uploads\/2019\/07\/discounts.xlsx\"]\n\n&lt;!-- We need to apply some behind-the-scenes number transformations to see if the discount is a fixed amount or a percentage. If the number is &gt;= 1, then it is a fixed discount, otherwise we assume it is a percentage --&gt;\n\n&lt;!-- First, round down to the nearest integer --&gt;\n[calculation temp cf7-hide precision:0 rounddown \"raw_discount\"]\n[calculation temp_2 cf7-hide precision:0 rounddown \"raw_discount_2\"]\n\n&lt;!-- Then, normalize to either 0 or 1 --&gt;\n[calculation is_fixed cf7-hide min:0 max:1 \"temp\"]\n[calculation is_fixed_2 cf7-hide min:0 max:1 \"temp_2\"]\n&lt;\/div&gt;\n\n&lt;!-- Calculate discount --&gt;\n&lt;label&gt;Discount: $ [calculation discount \"raw_discount * is_fixed + (subtotal * raw_discount * (1-is_fixed)) + raw_discount_2 * is_fixed_2 + (subtotal * raw_discount_2 * (1-is_fixed_2))\"]&lt;\/label&gt;\n\n&lt;!-- Calculate total --&gt;\n&lt;label&gt;Total: $ [calculation total \"subtotal - discount\"]\n&lt;\/label&gt;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a very simple example of how you can implement discount codes managed in a separate Excel file on the server. Try these codes: TESTPERCENT &#8211; percentage discount, 20% TESTFIXED &#8211; fixed discount of $5 You can download the Excel spreadsheet here. Source code for this form: &lt;label&gt;Subtotal ($): $ [text subtotal &#8220;1000&#8221;]&lt;\/label&gt; &lt;label&gt;Discount [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-216","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/pages\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":7,"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/pages\/216\/revisions"}],"predecessor-version":[{"id":519,"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/pages\/216\/revisions\/519"}],"up":[{"embeddable":true,"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/bossakov.eu\/wpdemo\/wp-json\/wp\/v2\/media?parent=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}