• Resolved mellow1

    (@cdsigns)


    We have a woocommerce store with checkbox in the backend to open and close the store. Inside child-themes functions.php there is a function that checks the box and adds appropriate class to body.

    The checkbox-update and body class only show after we manually hit “Purge SG Cache” from the backend.

    We wish include this through the functions, but so far no luck. If we change the checkbox, the bodyclass only shows after manual purge.

    The snippet of the bodyclass code is below. Could you help us out, we are probably missing something here.

    For testing purposes we added both the purge-codes you provided. But nothing happens, unless we use the backend button to purge.

    //
    // add class on checkbox
    function my_body_classes( $classes ) {
    
    if (function_exists('sg_cachepress_purge_everything')) {
                sg_cachepress_purge_everything();
        }
    
        if (function_exists('sg_cachepress_purge_cache')) {
                sg_cachepress_purge_cache();
        }
    
    if( wfs_is_service_enabled()   ) {
    		$classes[] = 'StoreIsNOTServing';
    }	
    	return $classes;
     
    }
    add_filter( 'body_class','my_body_classes' );
    • This topic was modified 3 years, 8 months ago by mellow1.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Stanimir Stoyanov

    (@sstoqnov)

    SiteGround Representative

    Hey @cdsigns

    Just move the purge function before you return the changed classes.

    
    // add class on checkbox
    function my_body_classes( $classes ) {
    	if( wfs_is_service_enabled()   ) {
    		$classes[] = 'StoreIsNOTServing';
    	}
    	if (function_exists('sg_cachepress_purge_everything')) {
    		sg_cachepress_purge_everything();
    	}
    	return $classes;
     
    }
    add_filter( 'body_class','my_body_classes' );

    Regards,
    Stanimir

    Thread Starter mellow1

    (@cdsigns)

    Hi Stanimir,

    Thank you so much for the amazingly fast reply and help.
    At first we did not notice a change, but we forgot to clear the browser cache for the admin (silly mistake) and now everything works like a charm!

    Have a great day,

    Best regards.

    Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    Awesome, glad that it’s now working fine for you ?? You can drop a quick review for the plugin if you have the time, that would be highly appreciated ??

    Thread Starter mellow1

    (@cdsigns)

    Hi @hristo-sg or @sstoqnov ,

    Recently we discovered that for one of our websites the code, you provided above does not seem to be working anymore.

    if our client checks or unchecks the box in the backend, the cache is no longer purged within the function. We need to perform a manual purge with the button in the backend. We are using 6.0.3 of your SG Optimizer plugin.

    Would you happen to have any idea what might be causing this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Purge cache function not working’ is closed to new replies.