Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Make my shortcode work with WP Super Cache WordPress


The following shortcode gets cached by WP Super Cache on my site, however I would like it to stay dynamic.

I've read about fragmented caching but don't really understand the concept, so I would like some help making my shortcode dynamic while using WP Super Cache.

The shortcode
function cart_notice() {
$maximum = 400;
$current = WC()->cart->subtotal;

if (sizeof(WC()->cart->get_cart()) !== 0) {
if ($woocommerce->cart->total < $maximum ) {
if ( $current < $maximum ) {
echo 'Køb for ' . ($maximum - $current) . ' kr mere og få <strong>gratis</strong> levering lige til døren!';
$output = ob_get_clean();
return $output;
add_action( 'woocommerce_before_cart', 'cart_notice' );
add_shortcode( 'cart_notice_sc', 'cart_notice' );

Answers (3)


Jayaram Y answers:

Hi Cruiseback,

Hope you are doing well. I remember the shot-code which is above was given by me.

Yes you can achieve this by doing some settings and adding up a plugin.

I can show you working example. Please add me on skype: jayaram558

Jayaram Y comments:

please check this link here:

Wp super cache is installed and running

Check the product description while adding the product to cart. I have set the min limit to 20. Once the 20 limit is reached, the shortcode disappears.

cruiseback comments:

Hi Jayram,

Thanks, and yes I remember you.

Can you send me the revised code so that I can test it live in our production environment?

Jayaram Y comments:

Its not the code cruiseback. its the process by adding a plugin and making few settings to wp super cache.

If you can come on skype or team-viewer i can show you so you can understand the process.

my email: [email protected]
skype: jayaram558


Francisco Javier Carazo Gil answers:


Caches doesn't work with shortcodes, they directly cache:
- each URL in a HTML file

So you shouldn't cache any page/URL in which this shortcode appears.

Francisco Javier Carazo Gil comments:

You should not cache any page of this.
My Account
Change Password
Edit Address
View Order
Order Received

And also, any other page in which your shortcode appears.


IndiTheme - answers:

if( !function_exists( 'woocommerce_mini_cart_menu_fragment' ) ) :
* Refresh mini cart when data product change.
function woocommerce_mini_cart_menu_fragment( $fragments ) {
$fragments[''] = ob_get_clean();
return $fragments;
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_mini_cart_menu_fragment' );

change <strong></strong> with <strong>your shortcode div.container</strong>
change <strong>woocommerce_mini_cart_menu()</strong> with <strong> your shortcode function</strong>