uritz
Forum Replies Created
-
Forum: Hacks
In reply to: Run a function only once – share variable across templates PHPYup, and its working great. ??
Forum: Hacks
In reply to: Run a function only once – share variable across templates PHPYes, awesome, this works great. To test it out, I did the following :
function get_rand_value() { if ( false === ( $value = get_transient( 'api_value' ) ) ) { $value = rand(0,10); set_transient( 'api_value', $value, 3600 ); // store for 3600s } return $value; }
And I called get_rand_value() in footer, so that it gets called on every template. Works great man, thanks. I would still like to learn if it is possible to put it in session, just for learning sake. ??
Forum: Hacks
In reply to: Run a function only once – share variable across templates PHPEsmi : I tried storing the variable in session, but on every page, value in the session variable changed, could you point me how to store it in a session properly ?
Catacaustic : Thanks for replying. I agree, I can use something like that to load a variable value once per page execution, but what I am looking for is something where I can store it for the entire time the user is on the website(session). Since, I don’t exactly know when the session gets over, it should have a timeout too. Lastly, I might even try storing the value in user’s cookie. If you have any idea in either direction or another idea, please point me towards it ??
Forum: Hacks
In reply to: Run a function only once – share variable across templates PHPI can as well call the API again and again. I can store the variable in the database, then for every product, I would have to make extra database calls for the variable. Plus, since the value of variable changes every second, it could and should be different for different customers, I should refrain from using the normalised value of the variable. Is there any other way ? ??
Forum: Hacks
In reply to: Run a function only once – share variable across templates PHPAah, but I cannot store the variable in the database, sorry I forgot to point that out.
Ohh, never mind thanks man. I played with some PHP files and got it working ??
Aww, I am sorry to hear that. But any help would still be appreciated ??
Hi,
Doesn’t matter. I resolved it, the plugin is working fine. Thanks for pointing out though. I have seen your profile and I know that you have done a lot of work on WooCommerce. I am currently developing an ecommerce website which supports BitPay. However, I would like to display both the product price in USD(say) and BTC at the same time, underneath the product.
I was reading a lot of WordPress Support Questions and a lot of them have the same problem/ want the same feature. Could you please guide me as to how I should go about it. I am still very new to WebDev and since you are so experienced any help would be appreciated.
Thank you.