Title: Exception function
Last modified: November 28, 2023

---

# Exception function

 *  Resolved [mohammadnrhi](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/)
 * 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)

1 [2](https://wordpress.org/support/topic/exception-function/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/exception-function/page/2/?output_format=md)

 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17240503)
 * please check our [ESI example](https://docs.litespeedtech.com/lscache/lscwp/api/#generate-esi-block-url)
 *  Thread Starter [mohammadnrhi](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17240978)
 * 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 solutionI display these two functions
   differently for each country based on IPWhat way do you suggest?
 *  Thread Starter [mohammadnrhi](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17241048)
 * [I found this in the docs](https://docs.litespeedtech.com/lsws/cp/cpanel/geoip/),
   
   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](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17241340)
 * 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](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17243977)
 * yes, the geoip must be enabled at server-level , ref: [https://docs.litespeedtech.com/lsws/cp/cpanel/geoip/](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](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17244227)
 * Can this be done with a free cdn?
 * Can you tell me how to do this with cdn?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17244246)
 * if you are using QC CDN , then add this at top of your .htaccess
 *     ```wp-block-code
       RewriteRule .* - [E=Cache-Control:vary=%{HTTP:x-qc-country}]
       ```
   
 * if you are using CF CDN, then add this at top of your .htaccess
 *     ```wp-block-code
       RewriteRule .* - [E=Cache-Control:vary=%{HTTP:CF-IPCountry}]
       ```
   
 *  Thread Starter [mohammadnrhi](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17244339)
 * Thanks and do they both offer this feature for free?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246675)
 * both have free plan.
 *  Thread Starter [mohammadnrhi](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246940)
 * 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](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246944)
 * please check this [ESI example](https://docs.litespeedtech.com/lscache/lscwp/api/#generate-esi-block-url)
 *  Thread Starter [mohammadnrhi](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246956)
 * Thanks, can you confirm this?
 * add this in my product page:
 *     ```wp-block-code
       <?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:
 *     ```wp-block-code
       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](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246959)
 * 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](https://wordpress.org/support/users/mohammadnrhi/)
 * (@mohammadnrhi)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246991)
 * 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 buttonOn the product page
 * And I have restricted the display of these functions based on IP
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/#post-17246992)
 * 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 `
 *     ```wp-block-code
       echo "my random number:".rand (1,99999);
       ```
   
 * but with ESI , you need to replace it to
 *     ```wp-block-code
       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
 *     ```wp-block-code
       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)

1 [2](https://wordpress.org/support/topic/exception-function/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/exception-function/page/2/?output_format=md)

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

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 17 replies
 * 2 participants
 * Last reply from: [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/exception-function/page/2/#post-17248079)
 * Status: resolved