You've already forked wc-licensed-product
Fix version upload handling and add better error logging
- Fix VersionManager::createVersion() to handle null attachment_id properly - Add product type validation in AJAX version handler - Add database error logging for debugging - Improve meta box visibility logic for licensed products - Add known bug note to CLAUDE.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,14 +46,23 @@ final class VersionAdminController
|
||||
*/
|
||||
public function addVersionsMetaBox(): void
|
||||
{
|
||||
add_meta_box(
|
||||
'wc_licensed_product_versions',
|
||||
__('Product Versions', 'wc-licensed-product'),
|
||||
[$this, 'renderVersionsMetaBox'],
|
||||
'product',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
global $post;
|
||||
|
||||
// Only add meta box for licensed products or new products
|
||||
if ($post && $post->post_type === 'product') {
|
||||
$product = wc_get_product($post->ID);
|
||||
// Show for licensed products or new products (where type might be selected later)
|
||||
if (!$product || $product->is_type('licensed') || $post->post_status === 'auto-draft') {
|
||||
add_meta_box(
|
||||
'wc_licensed_product_versions',
|
||||
__('Product Versions', 'wc-licensed-product'),
|
||||
[$this, 'renderVersionsMetaBox'],
|
||||
'product',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,6 +260,16 @@ final class VersionAdminController
|
||||
wp_send_json_error(['message' => __('This version already exists.', 'wc-licensed-product')]);
|
||||
}
|
||||
|
||||
// Verify product exists and is of type licensed
|
||||
$product = wc_get_product($productId);
|
||||
if (!$product) {
|
||||
wp_send_json_error(['message' => __('Product not found.', 'wc-licensed-product')]);
|
||||
}
|
||||
|
||||
if (!$product->is_type('licensed')) {
|
||||
wp_send_json_error(['message' => __('This product is not a licensed product.', 'wc-licensed-product')]);
|
||||
}
|
||||
|
||||
$newVersion = $this->versionManager->createVersion(
|
||||
$productId,
|
||||
$version,
|
||||
@@ -260,7 +279,12 @@ final class VersionAdminController
|
||||
);
|
||||
|
||||
if (!$newVersion) {
|
||||
wp_send_json_error(['message' => __('Failed to create version.', 'wc-licensed-product')]);
|
||||
global $wpdb;
|
||||
$errorMessage = __('Failed to create version.', 'wc-licensed-product');
|
||||
if (!empty($wpdb->last_error)) {
|
||||
error_log('WC Licensed Product: DB error - ' . $wpdb->last_error);
|
||||
}
|
||||
wp_send_json_error(['message' => $errorMessage]);
|
||||
}
|
||||
|
||||
wp_send_json_success([
|
||||
|
||||
Reference in New Issue
Block a user