Fix WooCommerce product sync button functionality

- Move sync handler from wc-integration.js to admin.js (uses wpBnbAdmin)
- Add CSS for button icon vertical alignment with inline-flex
- Add spin animation for sync button icon during operation
- Add sync status styling (success/error colors)
- Add i18n strings for syncing messages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 10:17:17 +01:00
parent ada838a1e4
commit c92be303e8
3 changed files with 90 additions and 0 deletions

View File

@@ -1199,6 +1199,51 @@
});
}
/**
* Initialize WooCommerce sync button.
*/
function initWooCommerceSync() {
var $syncBtn = $('.bnb-sync-rooms-btn');
if (!$syncBtn.length) {
return;
}
$syncBtn.on('click', function(e) {
e.preventDefault();
var $btn = $(this);
var $status = $btn.siblings('.sync-status');
$btn.prop('disabled', true);
$btn.find('.dashicons').addClass('bnb-spin');
$status.text(wpBnbAdmin.i18n.syncing || 'Syncing...');
$.ajax({
url: wpBnbAdmin.ajaxUrl,
type: 'POST',
data: {
action: 'wp_bnb_sync_all_rooms',
nonce: wpBnbAdmin.nonce
},
success: function(response) {
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>');
}
},
error: function() {
$status.html('<span class="bnb-sync-error">' + (wpBnbAdmin.i18n.error || 'Error occurred') + '</span>');
},
complete: function() {
$btn.prop('disabled', false);
$btn.find('.dashicons').removeClass('bnb-spin');
}
});
});
}
// Initialize on document ready.
$(document).ready(function() {
initLicenseManagement();
@@ -1214,6 +1259,7 @@
initBookingServices();
initDashboardCharts();
initReportsPage();
initWooCommerceSync();
});
})(jQuery);