Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpmu_form_ex_get_submissions( $order_id ) {
- $sub_count = array();
- // connect to external DB
- $edb_host = '';
- $edb_pass = '';
- $edb_user = '';
- $edb_dbname = '';
- $external_db = new wpdb( $edb_user, $edb_pass, $edb_dbname, $edb_host );
- // get max submissions allowed
- $results = $external_db->get_results( $external_db->prepare( "SELECT `Identity_Number_Totals` FROM `shop_donor_card_purchases` WHERE `Order_ID` = %s", $order_id ) );
- $sub_count['max'] = $results[0]->Identity_Number_Totals;
- // get current number of submissions
- $results = $external_db->get_results( $external_db->prepare( 'SELECT COUNT(`Order_ID`) AS `remain` FROM `shop_donor_card_purchases_print` WHERE `Order_ID` = %s', $order_id ) );
- $sub_count['count'] = $results[0]->remain;
- // calculate remaining allowed submissions (max - existing)
- $sub_count['remaining'] = $sub_count['max'] - $sub_count['count'];
- // and return
- return $sub_count;
- }
- add_filter( 'forminator_render_form_markup', 'wpmu_form_ex_prerender', 10, 4);
- function wpmu_form_ex_prerender( $html, $form_fields, $form_type, $form_settings ) {
- // execute only if specific form is displayed (replace number with your form ID
- if ($form_settings['form_id'] == '13660' ) {
- // get Order ID from URL (see commented out function at the bottom of this code)
- $order_id = get_query_var( 'order_id' );
- // get submissions (maximum allowed, number of made already and calculate remaining)
- $submission_count = wpmu_form_ex_get_submissions( $order_id );
- // create custom above the form messsage
- $my_header = '<div class="forminator_limit_info">
- <p>Your ORDER ID: '. $order_id . '</p>
- <p>Remaining submissions: ' . $submission_count['remaining'] . ' of ' . $submission_count['max'] . '</p>
- </div>';
- // if there are remaining submissions, output custom header info and form
- // otherwise "destroy" the form and output only custom header
- if ( $submission_count['remaining'] > 0 ) {
- $html = $my_header . $html;
- }
- else {
- $html = $my_header;
- }
- }
- return $html;
- }
- //if you don't see actual ORDER ID above the form but only the "Your Order ID:" message
- // without actual ID, uncomment below code:
- //function wpmu_form_ex_query_vars( $qvars ) {
- // $qvars[] = 'DataProc';
- // return $qvars;
- //}
- //add_filter( 'query_vars', 'wpmu_form_ex_query_vars' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement