{"id":12056477,"date":"2019-10-23T07:23:50","date_gmt":"2019-10-23T07:23:50","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/how-to-call-a-function-from-functions-php-on-button-click-event\/"},"modified":"2019-10-23T07:23:50","modified_gmt":"2019-10-23T07:23:50","slug":"how-to-call-a-function-from-functions-php-on-button-click-event","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/how-to-call-a-function-from-functions-php-on-button-click-event\/","title":{"rendered":"How to call a function from functions.php on button click event?"},"content":{"rendered":"<p>i have the function below on function.php<\/p>\n<pre><code>\/**\n * Set a minimum order amount for checkout\n *\/\n add_action( &#039;woocommerce_checkout_process&#039;, &#039;wc_minimum_order_amount&#039; );\n add_action( &#039;woocommerce_before_cart&#039; , &#039;wc_minimum_order_amount&#039; );\n\nfunction wc_minimum_order_amount($min_amount) {\n\/\/ Set this variable to specify a minimum order value\n\/\/$minimum = $(&#039;#amount&#039;).val(); \n\/\/$minimum = 30; \n\n$minimum = $min_amount; \n\nif ( WC()-&gt;cart-&gt;total &lt; $minimum ) {\n\n    if( is_cart() ) {\n\n        wc_print_notice( \n            sprintf( &#039;Your current order total is %s \u2014 you must have an order with a minimum of %s to place your order.&#039; , \n                wc_price( WC()-&gt;cart-&gt;total ), \n                wc_price( $minimum )\n            ), &#039;error&#039; \n        );\n\n    } else {\n\n        wc_add_notice( \n            sprintf( &#039;Your current order total is %s \u2014 you must have an order with a minimum of %s to place your order.&#039; , \n                wc_price( WC()-&gt;cart-&gt;total ), \n                wc_price( $minimum )\n            ), &#039;error&#039; \n        );\n\n    }\n}\n}<\/code><\/pre>\n<p>Also, i have an input field and a button <\/p>\n<pre><code>&lt;form&gt;\n &lt;input type=&quot;text&quot; id=&quot;amount&quot; name=&quot;min_amount_ID&quot;\/&gt;\n&lt;input type=&quot;button&quot; onclick=&quot;wc_minimum_order_amount(this.form.min_amount_ID.value)&quot; class=&quot;min_amount&quot;\/&gt;\n&lt;\/form&gt;<\/code><\/pre>\n<p>How can i call the function wc_minimum_order_amount() from function.php file on click button?<br \/>\nOr how i can use the result of the script below inside wc_minimum_order_amount() function and assign it as a result to the variable $minimum ?<\/p>\n<pre><code>   &lt;script type=&quot;text\/javascript&quot;&gt;\n $(document).ready(function(){\n   $(&#039;.min_amount&#039;).on(&#039;click&#039;, function(){\n    var text_val = $(&#039;#amount&#039;).val();\n   \/\/alert(text_val );\n      });\n });\n&lt;\/script&gt;<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-12056477","topic","type-topic","status-publish","hentry","topic-tag-function-php"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12056477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12056477\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12056477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}