• Resolved mohammadnrhi

    (@mohammadnrhi)


    Hello, I cache my WooCommerce product page, I call a function on the product page, I want to set this function as an exception so that it is not cached, but the rest of the product page is.
    How should I do this?

    My functions:

    az_product_price_woo( get_the_ID() );
    az_add_product_woo( get_the_ID() );

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Support qtwrk

    (@qtwrk)

    please check our ESI example

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    I read about esi, and it’s exactly what I want, but my hosting manager won’t enable it.
    Therefore, I am looking for another solution
    I display these two functions differently for each country based on IP
    What way do you suggest?

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    I found this in the docs,
    I use WooCommerce and maxmind, I have enabled maxmind through WooCommerce settings.
    And I have set the Default customer address to Geolocate and the IP identification works successfully.
    Now I want to know, to use the following code, the hosting manager should activate something?:

    <IfModule LiteSpeed> RewriteEngine on RewriteRule .* - [E=Cache-Control:vary=%{ENV:GEOIP_COUNTRY_CODE}] </IfModule>

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    I tested this and it didn’t work, the hosting manager also said that it can’t enable this, is there another solution?

    Plugin Support qtwrk

    (@qtwrk)

    yes, the geoip must be enabled at server-level , ref: https://docs.litespeedtech.com/lsws/cp/cpanel/geoip/

    otherwise you need to have a CDN service like QUIC cloud or CloudFlare that gives the http request header with country info.

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    Can this be done with a free cdn?

    Can you tell me how to do this with cdn?

    Plugin Support qtwrk

    (@qtwrk)

    if you are using QC CDN , then add this at top of your .htaccess

    RewriteRule .* - [E=Cache-Control:vary=%{HTTP:x-qc-country}]

    if you are using CF CDN, then add this at top of your .htaccess

    RewriteRule .* - [E=Cache-Control:vary=%{HTTP:CF-IPCountry}]
    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    Thanks and do they both offer this feature for free?

    Plugin Support qtwrk

    (@qtwrk)

    both have free plan.

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    Hello again, I have good news, I found a hosting that they enable esi
    I wanted to see how to determine these two functions so that they are not cached? I’m not good at coding and the example I saw for esi was to add a word to the beginning of the shortcode but it’s not a shortcode! its function.
    Can you please add esi to these functions? with 0 ttl

    az_product_price_woo( get_the_ID() );
    az_add_product_woo( get_the_ID() );

    And if I need to add another code other than this code, somewhere else, please tell me

    Plugin Support qtwrk

    (@qtwrk)

    please check this ESI example

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    Thanks, can you confirm this?

    add this in my product page:

    <?php
    
    echo apply_filters( 'litespeed_esi_url', 'my_esi_block', 'Custom ESI block' );
    az_product_price_woo( get_the_ID() );
    az_add_product_woo( get_the_ID() );
    ?>

    then add this in my functions.php:

    add_action( 'litespeed_esi_load-my_esi_block', 'my_esi_block_esi_load' );
    
    function my_esi_block_esi_load()
    {
    do_action( 'litespeed_control_set_nocache' );
    az_product_price_woo( get_the_ID() );
    az_add_product_woo( get_the_ID() );
    }
    Plugin Support qtwrk

    (@qtwrk)

    what does these 2 functions output and where does it output to ?

    you need to replace and warp it to ESI block.

    Thread Starter mohammadnrhi

    (@mohammadnrhi)

    So you want to tell me that a function cannot be ESI. It is true? Should the initial code be ESI?

    The first function displays the price
    And the second function conditionally displays the add to cart or download button
    On the product page

    And I have restricted the display of these functions based on IP

    Plugin Support qtwrk

    (@qtwrk)

    you need to run that apply_fitler(esi….) in the place where you currently display your functions output , and then link it to the ESI function wrapped

    in the documented example , let’s say I have somewhere in my page to display a random number , without cache , you just put `

    echo "my random number:".rand (1,99999);

    but with ESI , you need to replace it to

    echo apply_filters( 'litespeed_esi_url', 'my_esi_block', 'Custom ESI block' );

    and then create the ESI function to contains your code , in this example , to be

    add_action( 'litespeed_esi_load-my_esi_block', 'my_esi_block_esi_load' );
    
    function my_esi_block_esi_load()
    {
    do_action( 'litespeed_control_set_nocache' );
    echo "my random number:".rand (1,99999);
    }
Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘Exception function’ is closed to new replies.