You've already forked wc-licensed-product
Implement multi-domain licensing for v0.5.0
- Add multi-domain checkout support for WooCommerce Blocks - Fix domain field rendering using ExperimentalOrderMeta slot - Add DOM injection fallback for checkout field rendering - Update translations with new multi-domain strings (de_CH) - Update email templates for grouped license display - Refactor account page to group licenses by product/order Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -208,15 +208,50 @@ final class Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
// Try new multi-domain format first
|
||||
$domainData = $order->get_meta('_licensed_product_domains');
|
||||
if (!empty($domainData) && is_array($domainData)) {
|
||||
$this->generateLicensesMultiDomain($order, $domainData);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back to legacy single domain format
|
||||
$this->generateLicensesSingleDomain($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate licenses for new multi-domain format
|
||||
*/
|
||||
private function generateLicensesMultiDomain(\WC_Order $order, array $domainData): void
|
||||
{
|
||||
$orderId = $order->get_id();
|
||||
$customerId = $order->get_customer_id();
|
||||
|
||||
// Index domains by product ID for quick lookup
|
||||
$domainsByProduct = [];
|
||||
foreach ($domainData as $item) {
|
||||
if (isset($item['product_id']) && isset($item['domains']) && is_array($item['domains'])) {
|
||||
$domainsByProduct[(int) $item['product_id']] = $item['domains'];
|
||||
}
|
||||
}
|
||||
|
||||
// Generate licenses for each licensed product
|
||||
foreach ($order->get_items() as $item) {
|
||||
$product = $item->get_product();
|
||||
if ($product && $product->is_type('licensed')) {
|
||||
$domain = $order->get_meta('_licensed_product_domain');
|
||||
if ($domain) {
|
||||
if (!$product || !$product->is_type('licensed')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$productId = $product->get_id();
|
||||
$domains = $domainsByProduct[$productId] ?? [];
|
||||
|
||||
// Generate a license for each domain
|
||||
foreach ($domains as $domain) {
|
||||
if (!empty($domain)) {
|
||||
$this->licenseManager->generateLicense(
|
||||
$orderId,
|
||||
$product->get_id(),
|
||||
$order->get_customer_id(),
|
||||
$productId,
|
||||
$customerId,
|
||||
$domain
|
||||
);
|
||||
}
|
||||
@@ -224,6 +259,29 @@ final class Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate licenses for legacy single domain format
|
||||
*/
|
||||
private function generateLicensesSingleDomain(\WC_Order $order): void
|
||||
{
|
||||
$domain = $order->get_meta('_licensed_product_domain');
|
||||
if (empty($domain)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($order->get_items() as $item) {
|
||||
$product = $item->get_product();
|
||||
if ($product && $product->is_type('licensed')) {
|
||||
$this->licenseManager->generateLicense(
|
||||
$order->get_id(),
|
||||
$product->get_id(),
|
||||
$order->get_customer_id(),
|
||||
$domain
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Twig environment
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user