{"id":1890,"date":"2022-07-29T15:36:47","date_gmt":"2022-07-29T13:36:47","guid":{"rendered":"https:\/\/www.areaweb.sk\/?p=1890"},"modified":"2022-08-18T10:03:43","modified_gmt":"2022-08-18T08:03:43","slug":"overenie-dlzky-tel-cisla","status":"publish","type":"post","link":"https:\/\/www.areaweb.sk\/cs\/overenie-dlzky-tel-cisla\/","title":{"rendered":"Overenie d\u013a\u017eky tel. \u010d\u00edsla"},"content":{"rendered":"<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.areaweb2.pppcreative.sk\/wp-content\/uploads\/2022\/07\/phone-check.jpg\" alt=\"overenie tel cisla woocomerce\" class=\"wp-image-1891\" width=\"423\" height=\"410\" srcset=\"https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/07\/phone-check.jpg 998w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/07\/phone-check-300x291.jpg 300w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/07\/phone-check-768x744.jpg 768w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/07\/phone-check-310x300.jpg 310w\" sizes=\"auto, (max-width: 423px) 100vw, 423px\" \/><figcaption>overenie tel cisla woocomerce<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>if ( document.querySelector('.checkout') ){\n\tdocument.getElementById('billing_phone').addEventListener('change', skontrolujCislo)  \/\/ alebo keyup\n}\n\nfunction skontrolujCislo () {\n    if(document.getElementById('billing_phone').value.length!=13 ) {\n    \tdocument.getElementById('place_order').disabled = true\n    }\n    else {\n\tdocument.getElementById('place_order').disabled = false\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Tento javascript vypne vo woocomerce tla\u010d\u00eddlo odosla\u0165 objedn\u00e1vku ak nie je d\u013a\u017eka telef\u00f3nneho \u010d\u00edsla 13 znakov.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const node = document.createElement(\"i\");\nconst textnode = document.createTextNode(\"Telef\u00f3nne \u010d\u00edslo uviest v tvare +421\");\nnode.appendChild(textnode);\ndocument.querySelector('#billing_phone').appendChild(node)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">T\u00fdmto scriptom zas prid\u00e1me element s textom pod input s telef\u00f3nnym \u010d\u00edslom.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Min. alebo max d\u013a\u017eku tel. \u010d\u00edsla v\u0161ak vieme nastavi\u0165 aj cez wordpress snippet:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter( 'woocommerce_checkout_fields', 'checkout_fields_custom_attributes', 9999 );\r\n \r\nfunction checkout_fields_custom_attributes( $fields ) {\r\n  \n  \/\/$fields&#91;'billing']&#91;'billing_phone']&#91;'maxlength'] = 10; \/\/ ak by sme chceli nastavi\u0165 max. d\u013a\u017eku staci prida\u0165 toto\n\r\n  \/\/V predvolenom nastaven\u00ed platobn\u00e9 polia WooCommerce podporuj\u00fa len niektor\u00e9 atrib\u00faty  napr. maxlenght \u00e1no ale minlenght nie tak\u017ee ho tam treba prida\u0165 jedn\u00fdm z t\u00fdchto sp\u00f4sobov\r\n \r\n  \/\/$fields&#91;'billing']&#91;'billing_phone']&#91;'custom_attributes'] = array( \"minlength\" => \"10\" ); \r\n  \/\/ $fields&#91;'billing']&#91;'billing_phone']&#91;'custom_attributes']&#91;'pattern'] = '.{15,}';   \/\/ ak by nefungovali prve 2 moznosti\r\n\r\n  $fields&#91;'billing']&#91;'billing_company']&#91;'custom_attributes']&#91;'minlength'] = 10;\r\n   return $fields;\r\n}\r\n\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0Tento snippet s\u00edce prid\u00e1 do pole poklad\u0148a atrib\u00fat minlenght ale  st\u00e1le sa odosiela, aj ke\u010f do\u0161lo k chybe pri zad\u00e1van\u00ed po\u013ea.\u00a0Tak\u017ee\u00a0<strong>bez oh\u013eadu na to, \u010do rob\u00edme, aj ke\u010f nastav\u00edme atrib\u00fat\u00a0<em>minlength<\/em>\u00a0, WooCommerce neoveruje vstupn\u00fa hodnotu po\u013ea pokladn<\/strong>e\u00a0.\u00a0Jedinou mo\u017enos\u0165ou ktor\u00fa m\u00e1me, je zastavi\u0165 proces platby, pokia\u013e  m\u00e1 pole viac ako  10 znakov.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ over\u00ed a  vyp\u00ed\u0161e error\r\nadd_action( 'woocommerce_checkout_process', 'checkout_fields_phone_validation' );\r\n   \r\nfunction checkout_fields_phone_validation() { \r\n   if ( isset( $_POST&#91;'billing_phone'] ) &amp;&amp; ! empty( $_POST&#91;'billing_phone'] ) ) {\r\n      if ( strlen( $_POST&#91;'billing_phone'] ) &lt; 10 ) {\r\n         wc_add_notice( 'Min. d\u013a\u017eka telef\u00f3nn\u00e9ho \u010d\u00edsla je 10 znakov.', 'error' );\r\n      }\r\n   }   \r\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Dostaneme tak\u00fdto v\u00fdsledok:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"256\" src=\"https:\/\/www.areaweb2.pppcreative.sk\/wp-content\/uploads\/2022\/08\/overenie-1024x256.png\" alt=\"\" class=\"wp-image-1982\" srcset=\"https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie-1024x256.png 1024w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie-300x75.png 300w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie-768x192.png 768w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie-650x163.png 650w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie-310x78.png 310w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie-150x38.png 150w, https:\/\/www.areaweb.sk\/wp-content\/uploads\/2022\/08\/overenie.png 1195w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Viac na: https:\/\/www.businessbloomer.com\/woocommerce-maxlength-minlength-checkout-fields\/<\/p>","protected":false},"excerpt":{"rendered":"<p>overenie tel cisla woocomerce if ( document.querySelector(&#8218;.checkout&#8216;) ){ document.getElementById(&#8218;billing_phone&#8216;).addEventListener(&#8218;change&#8216;, skontrolujCislo) \/\/ alebo keyup } function skontrolujCislo () {\u2026<\/p>","protected":false},"author":1,"featured_media":1891,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,26],"tags":[],"class_list":["post-1890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-js","category-woocomerce"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/1890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/comments?post=1890"}],"version-history":[{"count":0,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/1890\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media\/1891"}],"wp:attachment":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media?parent=1890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/categories?post=1890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/tags?post=1890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}