BrightWoocommerceIntegration::getBrightMultiLicenseData

BrightWoocommerceIntegration::getBrightMultiLicenseData

Overview

On a classic (single-key) license order, custom code can read the key with:

$license_key = BrightWoocommerceIntegration::getBrightLicenseId($order);

Multi-license orders do not store a single bright_license_id. They store several keys in order meta bright_multi_license_data.

BrightWoocommerceIntegration::getBrightMultiLicenseData($order) is the multi-license analogue of getBrightLicenseId(). It returns the same data Bright uses to build the license table on the WooCommerce order-received / view-order page.

$parsed = BrightWoocommerceIntegration::getBrightMultiLicenseData($order);

Use it anywhere you need programmatic access to the keys on a multi-license order: custom templates, reports, admin tools, or email.

Requirements

  • Bright WooCommerce integration enabled in the Bright plugin
  • Enforce Multilicense Orders enabled (experimental)
  • The order has already been managed by Bright, so multi-license data exists on the order

Return Data

$parsed = BrightWoocommerceIntegration::getBrightMultiLicenseData($order);

$parsed is an array with three keys:

Key What it is When to use it
entries Rows of name (the license key) and course_guids Prefer this. This is the structured payload used by the order-received table.
license_keys De-duplicated list of key name strings Fallback when entries is empty (name-only or comma-separated meta).
course_title_map course_guid => course title Look up titles when looping entries. If a GUID is missing, show the GUID.

If the argument is not a WC_Order, or the order has no multi-license data, all three arrays are empty.

Calling it

Detect a multi-license order, then read the payload:

if (BrightWoocommerceIntegration::isMultiLicenseOrder($order)) {
  $parsed = BrightWoocommerceIntegration::getBrightMultiLicenseData($order);
  // use $parsed['entries'] or $parsed['license_keys']
} elseif (BrightWoocommerceIntegration::isLicenseOrder($order)) {
  $license_key = BrightWoocommerceIntegration::getBrightLicenseId($order);
}

Keep both paths if the site still has older single-key orders.

Entries contains full data structure of license keys and associated course GUIDs.

foreach ($parsed['entries'] as $entry) {
  $key = $entry['name'];
  foreach ($entry['course_guids'] as $guid) {
    $title = isset($parsed['course_title_map'][$guid]) ? $parsed['course_title_map'][$guid] : $guid;
    // $key, $title
  }
}

license_keys is a flat list of the license keys, with no guid data.

foreach ($parsed['license_keys'] as $key) {
  // $key only; no course list
}

Redeem and report URLs

Bright’s URL helpers produce the same redeem and learners-report links as the thank-you page:

  • \Bright\WC\get_license_key_url($license_key)
  • \Bright\WC\get_license_key_report_url($license_key)

Those URLs can be rewritten with bright_woocommerce_license_key_url and bright_woocommerce_license_key_report_url. See Bright WooCommerce Integrations Actions And Filters.

Optional: parse stored meta without an order object

If you already have the bright_multi_license_data value (for example from the order admin editor):

$parsed = BrightWoocommerceIntegration::parseBrightMultiLicenseData($raw_data);

The return shape is the same as getBrightMultiLicenseData().

Notes

  • This is not the same as the filter bright_woocommerce_license_order_completed_email_text. That filter only changes the intro sentence above the table on the order details page. It does not receive the order and does not return license keys.
  • Do not call \Bright\WC\generate_order_details() unless you are rendering inside WooCommerce’s order-details table. It emits <tr> rows plus copy-to-clipboard JavaScript meant for that page.

Troubleshooting

If the function returns empty arrays:

  • confirm the order is a multi-license order (isMultiLicenseOrder())
  • confirm Bright has already created keys (order notes / Multi-License Data editor)
  • if entries is empty, check license_keys — older or partial meta may only have names

Use case: include the keys in a completed-order email

Bright’s default completed-order email still only injects the intro text from Bright → WooCommerce → Email Text (usually a link to view the order). It does not include the multi-license table. See Changing Order Completed Email Text.

To put keys in the email, hook WooCommerce’s woocommerce_email_before_order_table (the same hook Bright uses for intro text) and render from getBrightMultiLicenseData().

add_action('woocommerce_email_before_order_table', 'my_bright_multilicense_email_table', 25, 4);

function my_bright_multilicense_email_table($order, $sent_to_admin, $plain_text, $email) {
  if ($email->id !== 'customer_completed_order') {
    return;
  }
  if (!BrightWoocommerceIntegration::isMultiLicenseOrder($order)) {
    return;
  }

  $parsed = BrightWoocommerceIntegration::getBrightMultiLicenseData($order);

  echo '<h2>Your license keys</h2>';
  echo '<table width="100%" cellpadding="6" cellspacing="0" border="1">';

  if (!empty($parsed['entries'])) {
    echo '<tr><th>License Key</th><th>Course Title</th><th>Redeem Link</th><th>Learners Report</th></tr>';
    foreach ($parsed['entries'] as $entry) {
      $key = $entry['name'];
      $redeem = \Bright\WC\get_license_key_url($key);
      $report = \Bright\WC\get_license_key_report_url($key);
      foreach ($entry['course_guids'] as $guid) {
        $title = isset($parsed['course_title_map'][$guid]) ? $parsed['course_title_map'][$guid] : $guid;
        echo '<tr>';
        echo '<td>' . esc_html($key) . '</td>';
        echo '<td>' . esc_html($title) . '</td>';
        echo '<td><a href="' . esc_url($redeem) . '">' . esc_html($redeem) . '</a></td>';
        echo '<td>';
        if (!empty($report)) {
          echo '<a href="' . esc_url($report) . '">' . esc_html($report) . '</a>';
        }
        echo '</td></tr>';
      }
    }
  } elseif (!empty($parsed['license_keys'])) {
    echo '<tr><th>License Key</th><th>Redeem Link</th></tr>';
    foreach ($parsed['license_keys'] as $key) {
      $redeem = \Bright\WC\get_license_key_url($key);
      echo '<tr><td>' . esc_html($key) . '</td>';
      echo '<td><a href="' . esc_url($redeem) . '">' . esc_html($redeem) . '</a></td></tr>';
    }
  }

  echo '</table>';
}

Put this in a small custom plugin or your theme’s functions.php. Confirm you hooked customer_completed_order — Bright’s built-in intro text only runs on that email.