Well, if anyone stumbles upon the same issue here’s my solution:
(function (originalFetch) {
window.fetch = function (...args) {
const url = args[0];
if (url.includes('/wp-json/bricksforge/v1/form_submit')) {
console.log('Bricksforge form submit detected via fetch');
}
return originalFetch.apply(this, args).then(response =>
response.json().then(json => {
const { results } = json;
if (results && results.success) {
results.success.forEach(({ action, type, finance_link }) => {
if (action === 'send_finance_lead' && type === 'success') {
console.log('Redirecting to finance link in 3 seconds...');
if (finance_link) {
setTimeout(() => {
console.log('Opening finance link:', finance_link);
window.open(finance_link, '_blank');
}, 3000);
}
}
});
}
return response; // Ensure the response is returned
})
);
};
})(window.fetch);