Fix WooCommerce sync button: AJAX handler registration and icon alignment

- Register ProductSync AJAX handler independently from full integration init
- AJAX now available on settings page even when integration is not yet enabled
- Improved icon vertical alignment with explicit margin-top adjustment
- Added better error handling and console logging in JS

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 10:22:14 +01:00
parent c92be303e8
commit 23f073339a
4 changed files with 49 additions and 8 deletions

View File

@@ -1213,7 +1213,7 @@
e.preventDefault();
var $btn = $(this);
var $status = $btn.siblings('.sync-status');
var $status = $btn.parent().find('.sync-status');
$btn.prop('disabled', true);
$btn.find('.dashicons').addClass('bnb-spin');
@@ -1230,11 +1230,19 @@
if (response.success) {
$status.html('<span class="bnb-sync-success">' + response.data.message + '</span>');
} else {
$status.html('<span class="bnb-sync-error">' + (response.data.message || 'Error') + '</span>');
var errorMsg = response.data && response.data.message ? response.data.message : 'Unknown error';
$status.html('<span class="bnb-sync-error">' + errorMsg + '</span>');
}
},
error: function() {
$status.html('<span class="bnb-sync-error">' + (wpBnbAdmin.i18n.error || 'Error occurred') + '</span>');
error: function(xhr, status, error) {
var errorMsg = wpBnbAdmin.i18n.error || 'Error occurred';
if (xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message) {
errorMsg = xhr.responseJSON.data.message;
} else if (error) {
errorMsg = error;
}
$status.html('<span class="bnb-sync-error">' + errorMsg + '</span>');
console.error('WP-BnB Sync Error:', status, error, xhr.responseText);
},
complete: function() {
$btn.prop('disabled', false);