Hello @babylon1999,
I mean this block https://img.alexodlw.beget.tech/2023-03-08_185140.png
The block is called “Filter by Stock”.
Let’s break down step by step how it is loaded
- The page is loaded
- When the page loads, this file /wp-content/plugins/woocommerce/packages/woocommerce-blocks/build/stock-filter-wrapper-frontend.js is called (or a file from your plugin)
- After processing the file this block appears https://img.alexodlw.beget.tech/2023-03-08_185140.png
What does it look like visually?
- When the page loads, the block is loaded https://img.alexodlw.beget.tech/2023-03-08_190129.png and something from the stock-filter-wrapper-frontend.js file is called
- After the stock-filter-wrapper-frontend.js file runs, the block appears as https://img.alexodlw.beget.tech/2023-03-08_185140.png
What is my problem?
I have other filters on my site, and when they work an ajax request occurs, which for some reason erases the HTML structure “Filter by Stock”. It goes like this https://img.alexodlw.beget.tech/bag.gif
That is, the block goes to the state https://img.alexodlw.beget.tech/2023-03-08_190129.png and further does not load
How I temporarily solved the problem?
I decided to call this block after AJAX request was loaded:
jQuery(document).ajaxStop(function() {
// here I call the code from your plugin
// woo-gutenberg-products-block/build/filter-wrapper-frontend.js
});
And magic… Everything works fine, but it looks terrible in the code https://img.alexodlw.beget.tech/2023-03-08_193517.png
What do I want to end up with?
Either way there should be a “Filter by Stock” initialization call or some kind of trigger or JS event that re-builds the HTML, it also works if I call all the code from the file
For example, on woocommerce there are such triggers https://img.alexodlw.beget.tech/2023-03-08_194047.png
In any case there should be some event on initialization of “Filter by Stock” so I can call it here:
jQuery(document).ajaxStop(function() {
// I want to trigger an event here that will display the block
});