php - Auto-populate input form field from URL parameters -


i have button on woocommerce page (http://.../product/abcd/) has button "book appointments now" links page form fields submit (http://.../booking-appointments/?id=1238&sku=1) has productid , sku on url of product previous page.

i want auto-populate productid field automatically each time page loads url parameters.

any appreciated.

to auto populate product id , product sku in booking form (page), should try (without guaranty can tested real on page form):

add_action( 'wp_footer', 'autopopulate_product_id_script' ); function autopopulate_product_id_script() {     if( isset( $_get['id'] ) ):         ?>         <script type="text/javascript">         (function($){             $('input[name="productid"]').val("<?php echo $_get['id']; ?>");             $('input[name="productsku"]').val("<?php echo $_get['sku']; ?>");         })(jquery);         </script>         <?php     endif; } 

code goes in function.php file of active child theme (or theme) or in plugin file.

the product id , product sku need passed in url like: http//www.example.com/booking-page/?id=124&&sku=ah1584

and <imput> text fields should like:

<input type="text" name="productid" val=""> <input type="text" name="productsku" val=""> 

so product sku similar, able add ease…

but javascript active in "easy appointments" booking form, don't know if work.


this answer related to: add custom "booking" button woocommerce product single pages


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -