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

@@ -11,6 +11,7 @@ namespace Jeremias\WcLicensedProduct\Product;
use Jeremias\WcLicensedProduct\Admin\SettingsController;
use WC_Product;
use Jeremias\WcLicensedProduct\Product\VersionManager;
/**
* Licensed Product type extending WooCommerce Product
@@ -121,11 +122,14 @@ class LicensedProduct extends WC_Product
}
/**
* Get current software version
* Get current software version (derived from latest product version)
*/
public function get_current_version(): string
{
return $this->get_meta('_licensed_current_version', true) ?: '';
$versionManager = new VersionManager();
$latestVersion = $versionManager->getLatestVersion($this->get_id());
return $latestVersion ? $latestVersion->getVersion() : '';
}
/**
@@ -133,12 +137,13 @@ class LicensedProduct extends WC_Product
*/
public function get_major_version(): int
{
$version = $this->get_current_version();
if (empty($version)) {
return 1;
$versionManager = new VersionManager();
$latestVersion = $versionManager->getLatestVersion($this->get_id());
if ($latestVersion) {
return $latestVersion->getMajorVersion();
}
$parts = explode('.', $version);
return (int) ($parts[0] ?? 1);
return 1;
}
}

View File

@@ -164,14 +164,6 @@ final class LicensedProductType
'value' => $currentBindToVersion ?: ($defaultBindToVersion ? 'yes' : 'no'),
'cbvalue' => 'yes',
]);
woocommerce_wp_text_input([
'id' => '_licensed_current_version',
'label' => __('Current Version', 'wc-licensed-product'),
'description' => __('Current software version (e.g., 1.0.0)', 'wc-licensed-product'),
'desc_tip' => true,
'placeholder' => '1.0.0',
]);
?>
</div>
</div>
@@ -223,12 +215,6 @@ final class LicensedProductType
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$bindToVersion = isset($_POST['_licensed_bind_to_version']) ? 'yes' : 'no';
update_post_meta($postId, '_licensed_bind_to_version', $bindToVersion);
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$currentVersion = isset($_POST['_licensed_current_version'])
? sanitize_text_field($_POST['_licensed_current_version'])
: '';
update_post_meta($postId, '_licensed_current_version', $currentVersion);
}
/**