Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. rafiahmedd renamed this gist May 19, 2022. 1 changed file with 0 additions and 0 deletions.
  2. rafiahmedd revised this gist May 19, 2022. No changes.
  3. rafiahmedd revised this gist Feb 27, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Block WpPayForm submission if maximum quantity limit reached
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,6 @@ add_filter('wppayform/validate_data_on_submission_item_quantity',function( $erro
    }
    }

    },10,4);
    },10,4);

    ?>
  4. rafiahmedd revised this gist Feb 27, 2022. 1 changed file with 1 addition and 0 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    add_filter('wppayform/validate_data_on_submission_item_quantity',function( $error, $elementId, $element, $form_data){
    global $wpdb;
    $formId = 46; //Please Add Your Form ID here
  5. rafiahmedd created this gist Aug 18, 2021.
    28 changes: 28 additions & 0 deletions Block WpPayForm submission if maximum quantity limit reached
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    add_filter('wppayform/validate_data_on_submission_item_quantity',function( $error, $elementId, $element, $form_data){
    global $wpdb;
    $formId = 46; //Please Add Your Form ID here
    $transactions = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpf_order_transactions WHERE form_id = {$formId}" );
    $orders = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpf_order_items WHERE form_id = {$formId}" );
    $orderQuantity = [];
    $limit = 10; //Please Add Your Total Limit Here

    for ($i = 0; $i < count($transactions); $i++) {
    $transId = $transactions[$i]->submission_id;
    $paymentStatus = $transactions[$i]->status;
    for ($j = 0; $j < count($orders); $j++) {
    if ($transId == $orders[$j]->submission_id && $paymentStatus == 'paid') {
    $orderQuantity[] = $orders[$j]->quantity;
    $remain = $limit - array_sum($orderQuantity);
    $temp = $remain;
    if ($temp < $form_data['item_quantity']) {
    if($temp<=0){
    return $error = "No tickets left.";
    }else{
    return $error = "A fewer tickets left.";
    }
    }
    }
    }
    }

    },10,4);