Home / eCommerce / Gravity Forms Hook — BOL Upload Triggers Capture
Duplicate Snippet

Embed Snippet on Your Site

Gravity Forms Hook — BOL Upload Triggers Capture

When the vendor uploads the Bill of Lading, the following snippet links the submission to the WooCommerce order and changes the status to Processing — which is the exact trigger WC Vendors Stripe Connect listens for to capture the payment.

The snippet detects the Order ID and file upload fields dynamically by label and field type, so no field IDs need to be hardcoded. Replace 5 with your actual Gravity Forms form ID.

To ensure the Order ID is automatically passed into the form:
- Add a Hidden field to your Gravity Form.
- Enable Allow field to be populated dynamically under the field's Advanced settings.
- Set the Parameter Name to order_id.
- Link to the form from the vendor order detail page with ?order_id=XXXX appended to the URL.

Gravity Forms will automatically populate the hidden field with the Order ID when the form loads.

Code Preview
php
<?php
  add_action( 'gform_after_submission_5', 'wcv_dynamic_bol_capture', 10, 2 );
  function wcv_dynamic_bol_capture( $entry, $form ) {
      $order_id     = null;
      $bol_file_url = null;
      foreach ( $form['fields'] as $field ) {
          $label = strtolower( trim( $field->adminLabel ?: $field->label ) );
          if ( in_array( $label, array( 'order id', 'order_id', 'orderid' ), true ) ) {
              $order_id = rgar( $entry, $field->id );
          }
          if ( 'fileupload' === $field->type && ! $bol_file_url ) {
              $bol_file_url = rgar( $entry, $field->id );
          }
      }
      if ( ! $order_id || ! $bol_file_url ) {
          return;
      }
      $order = wc_get_order( absint( $order_id ) );
      if ( ! $order ) {
          return;
      }
      $order->update_meta_data( '_bill_of_lading_url', esc_url_raw( $bol_file_url ) );
      $order->add_order_note( sprintf(
          __( 'Bill of Lading uploaded by vendor. Link: %s', 'wc-vendors' ),
          $bol_file_url
      ) );
      $order->update_status( 'processing', __( 'BOL uploaded. Payment capture triggered.', 'wc-vendors' ) );
  }

Comments

Add a Comment