So I ran into an issue where permalinks were failing for WooCommerce.  I was able to track down the issue in a custom plugin that was using the code example below.  From the custom plugin the flushrewriterules function was getting called in every init call which means every time a page gets loaded.  Upon reading more about the function flushrewriterules and how resource heavy it is can cause issues.

So finding that flushrewriterules is very resource heavy and tracking down the issue that other permalinks work properly when this line is commented out made me look at this more. I came to the realization that this function should not be called with every page load and should only be run when settings are changed and the rewrites need to be flushed.  So to get this working I modified the customRules function to not have the flushrewriterules in it.  Then in the custom plugins settings page I modified it so it had a call to flushrewriterules upon saving when on this settings page.

This allowed for the resource heavy flushrewriterules to not get called every time a page got loaded but only refreshed when needed.  So on the admin side when the settings got saved a simple call to customUponSaveSettings function allowed for the settings page to flush the rewrite rules.

%d bloggers like this: