• Resolved magestyx

    (@magestyx)


    We’ve been trying for two days now to get W3 Page Caching working with fragment caching properly. Our site uses the latest wordpress, elementor, woocommerce, etc. and we found right after going live an issue where Booster’s multicurrency plugin’s content gets cached like all other page content. So someone from region-A goes to the site and the currency is auto-set-by-region, that builds the page cache. Then when someone from region-B goes to the site, all currency info and pricing are already ‘pre-set’ from the cache created by the region-A user. Not good.

    Now – we eventually got code like below to work (< and > replaced with = so the code will display here):
    =!–mfunc FRAGMENT_CACHING –=
    echo date(“H:i:s”);
    =!–/mfunc FRAGMENT_CACHING –=

    But we’ve tried every method and combination trying to get a shortcode to work, like:
    =!–mfunc FRAGMENT_CACHING –=
    echo do_shortcode(‘[all_tracking]’);
    =!–/mfunc FRAGMENT_CACHING –=

    All this shortcode currently does is output the user’s IP address via 2 different means – very simple. The problem is that in the cached file, examples like the first one above are preserved because they haven’t run yet, but the 2nd example with the shortcode has the shortcode already run and so it’s saved in the cache file like:
    =!–mfunc FRAGMENT_CACHING –=
    echo do_shortcode(‘REMOTE_ADDR: 47.128.xx.xx
    HTTP_X_FORWARDED_FOR: 47.128.xx.xx

    ‘);
    =!–/mfunc FRAGMENT_CACHING –=

    When the page is then requested, there is of course no shortcode with such a name so the page simply outputs the contents between the (‘ and ‘) – resulting in essentially the same result if we hadn’t done the mfunc stuff to begin with.
    So how do we get the shortcode to be preserved as the actual pre-processed code?:
    echo do_shortcode(‘[all_tracking]’);

    Thanks!

    • This topic was modified 6 months, 1 week ago by magestyx.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter magestyx

    (@magestyx)

    Update:
    One of many alternatives we’ve tried is (spaces between & and # added so the characters will display here):
    echo do_shortcode(‘& #91;all_tracking& #93;’);

    The encoded brackets are saved to the cached file, though, so when do_shortcode happens it still can’t find a shortcode with that name – so the final output is simply [all_tracking]

    • This reply was modified 6 months, 1 week ago by magestyx.
    • This reply was modified 6 months, 1 week ago by magestyx.
    • This reply was modified 6 months, 1 week ago by magestyx.
    Thread Starter magestyx

    (@magestyx)

    Ok we finally got something working, but it’s well short of a full solution.

    We setup a new shortcode so that the ‘final’ shortcode is wrapped like: [shortcode_wrapper shortcode=”all_tracking”]

    The shortcode does (again, all <> are = so the code will display here):
    $content = ”;
    $shortcode = $atts[‘shortcode’];
    =!– mfunc FRAGMENT_CACHING –= echo do_shortcode(‘[” . $shortcode . “]’);=!– /mfunc FRAGMENT_CACHING –=
    return $content;

    This is confirmed working.
    BUT, the Product Price is an elementor woocommerce widget block. How do we apply this fragment cache to them?

    • This reply was modified 6 months, 1 week ago by magestyx.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @magestyx

    Thank you for your feedback.

    Can you please sahre the URL of the plugin you are using for currency switching?
    Also, have you made suyre that the mfunc code begins after the closed php tag and it’s not within the php tag:

    ?>
    <!-- mfunc mysecurestring -->
    
    <!-- /mfunc mysecurestring -->
    <?php

    Thanks!

    Thread Starter magestyx

    (@magestyx)

    Sure – here you go:
    https://booster.io/features/woocommerce-multicurrency-currency-switcher/

    The mfunc code is output by the PHP via the shortcode. We’re using Elementor for building the pages so we’re not doing any direct editing of any PHP theme files. So there’s no place we’re adding new code inline in any PHP. That may be easier ultimately, but I’m not sure how we’d do that building everything with Elementor blocks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fragment Cache with Shortcode results in same cached output’ is closed to new replies.