Implement version 0.0.8 features

- Remove Current Version field from product license settings
- Derive current version from latest product version in database
- Refactor email system to use WooCommerce email notification classes
- Add LicenseExpirationEmail WC_Email class for expiration warnings
- Add customizable email templates (HTML and plain text)
- Update settings to link to WooCommerce email configuration
- Update translations for new email-related strings

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-21 20:55:28 +01:00
parent 50388c2019
commit c6726703e4
13 changed files with 713 additions and 206 deletions

View File

@@ -92,6 +92,44 @@ final class SettingsController
'type' => 'sectionend',
'id' => 'wc_licensed_product_section_defaults_end',
],
// Email settings section
'email_section_title' => [
'name' => __('Expiration Warning Schedule', 'wc-licensed-product'),
'type' => 'title',
'desc' => sprintf(
/* translators: %s: URL to WooCommerce email settings */
__('Configure when expiration warning emails are sent. To customize the email template, enable/disable, or change the subject, go to %s.', 'wc-licensed-product'),
'<a href="' . esc_url(admin_url('admin.php?page=wc-settings&tab=email&section=wclp_license_expiration')) . '">' .
__('WooCommerce > Settings > Emails > License Expiration Warning', 'wc-licensed-product') . '</a>'
),
'id' => 'wc_licensed_product_section_email',
],
'expiration_warning_days_first' => [
'name' => __('First Warning (Days Before)', 'wc-licensed-product'),
'type' => 'number',
'desc' => __('Days before expiration to send the first warning email.', 'wc-licensed-product'),
'id' => 'wc_licensed_product_expiration_warning_days_first',
'default' => '7',
'custom_attributes' => [
'min' => '1',
'step' => '1',
],
],
'expiration_warning_days_second' => [
'name' => __('Second Warning (Days Before)', 'wc-licensed-product'),
'type' => 'number',
'desc' => __('Days before expiration to send the second warning email. Set to 0 to disable.', 'wc-licensed-product'),
'id' => 'wc_licensed_product_expiration_warning_days_second',
'default' => '1',
'custom_attributes' => [
'min' => '0',
'step' => '1',
],
],
'email_section_end' => [
'type' => 'sectionend',
'id' => 'wc_licensed_product_section_email_end',
],
];
}
@@ -139,4 +177,37 @@ final class SettingsController
{
return get_option('wc_licensed_product_default_bind_to_version', 'no') === 'yes';
}
/**
* Check if expiration warning emails are enabled
* This checks both the WooCommerce email setting and the old setting for backwards compatibility
*/
public static function isExpirationEmailsEnabled(): bool
{
// Check WooCommerce email enabled status
$emailEnabled = get_option('woocommerce_wclp_license_expiration_settings');
if (is_array($emailEnabled) && isset($emailEnabled['enabled'])) {
return $emailEnabled['enabled'] === 'yes';
}
// Default to enabled if not yet configured
return true;
}
/**
* Get first warning days before expiration
*/
public static function getFirstWarningDays(): int
{
$value = get_option('wc_licensed_product_expiration_warning_days_first', 7);
return max(1, (int) $value);
}
/**
* Get second warning days before expiration
*/
public static function getSecondWarningDays(): int
{
$value = get_option('wc_licensed_product_expiration_warning_days_second', 1);
return max(0, (int) $value);
}
}

View File

@@ -263,9 +263,6 @@ final class VersionAdminController
wp_send_json_error(['message' => __('Failed to create version.', 'wc-licensed-product')]);
}
// Also update the product's current version meta
update_post_meta($productId, '_licensed_current_version', $version);
wp_send_json_success([
'message' => __('Version added successfully.', 'wc-licensed-product'),
'version' => $newVersion->toArray(),