• Resolved pavelevap

    (@pavelevap)


    Hi,

    what is the point of your custom function wp_footer()?

    jQuery.cookie('woocommerce_cart_hash', null, {path: '/'});

    This is deprecated and null is converted to string.

    And that is why all sites using WooCommerce Currence Switcher have one more Ajax request ?wc-ajax=get_refreshed_fragments for every page. WooCommerce is checking for cookie_hash and it returns string null which is compared with empty cart_hash and it returns false In the end this Ajax request is processed on every page load and leads to slowing website ??

    Thank you for your help!

    • This topic was modified 8 years, 4 months ago by pavelevap.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello

    This is deprecated and null is converted to string. – Yes, but it is necessary for customers who still use woo 2.4

    If you remove this feature then the currency will not chang in a cart. All that we can offer you,-
    if(isset($_GET[‘currency’])){
    ?>
    <script type=”text/javascript”>
    try {
    jQuery(function () {
    jQuery.cookie(‘woocommerce_cart_hash’, null, {path: ‘/’});
    });
    } catch (e) {

    }
    </script>
    <?php
    }

    Thread Starter pavelevap

    (@pavelevap)

    So, null as a string is expected and it is based on depracated behaviour?

    OK, I am not sure why it is needed for older versions, but what about removing it for WooCommerce 2.5 and newer (most of websites)? You can add a small check for WooCommerce version to this function and remove one Ajax request for them?

    Hello

    I will correct it in the next update

    Plugin Author RealMag777

    (@realmag777)

    Hello

    woocommerce_cart_hash‘ – is not deprecated or removed and uses in the latest woocommerce in file wp-content\plugins\woocommerce\assets\js\frontend\cart-fragments.js and in wp-content\plugins\woocommerce\includes\class-wc-cart.php, so it will not be removed BUT this script will be working only currency changing is going https://clip2net.com/s/3Ed9lB9

    null is replaced to the empty string

    • This reply was modified 8 years, 3 months ago by RealMag777.
    • This reply was modified 8 years, 3 months ago by RealMag777.
    Thread Starter pavelevap

    (@pavelevap)

    Hi,

    I did not talk about woocommerce_cart_hash which is not deprecated ??
    I meant following code:

    jQuery.cookie('woocommerce_cart_hash', null, {path: '/'});

    This should create woocommerce_cart_hash cookie with null value (empty). But this call is deprecated and it leads to creating cookie with string 'null' which is not empty. And that is why Ajax request ?wc-ajax=get_refreshed_fragments is running for every page.

    Plugin Author RealMag777

    (@realmag777)

    Hello

    Sure ‘null’ is replaced already to the empty string ”.

    ?wc-ajax=get_refreshed_fragments – is not request of WOOCS, its standard woocommerce request which can be disabled by wc-cart-fragments:
    https://clip2net.com/s/3ElrtuT
    +
    https://www.ads-software.com/support/topic/wc-ajaxget_refreshed_fragments-1/ – so maybe in your case better to disable it

    Also set ‘IF’ checking in index.php of WOOCS – https://clip2net.com/s/3Ed9lB9

    • This reply was modified 8 years, 3 months ago by RealMag777.
    Thread Starter pavelevap

    (@pavelevap)

    Hi,

    no, everytime when I refresh my page, I can see woocommerce_cart_hash cookie with 'null' value as a string (and not empty).

    ?wc-ajax=get_refreshed_fragments is a standard WooCommerce request (and I do not want to disable it), but it is running only once and then local storage is used. But when WOOCS plugin is replacing value of related cookie by 'null' value, then it breaks this behaviour and Ajax request is running on each request for all websites.

    You can simply test it by using latest Storefront theme and clean WordPress installation (with Chrome developer tools). When you go to site homepage then ?wc-ajax=get_refreshed_fragments is running only on first request (when you browse other pages, there is no other similar request). But when you activate WOOCS, then this Ajax request is running for every page and slowing the whole website down.

    Plugin Author RealMag777

    (@realmag777)

    Hello

    In such case just remove jQuery.cookie('woocommerce_cart_hash', null, {path: '/'}); and try
    +
    Have you tried set conditions for ‘woocommerce_cart_hash’ code – https://clip2net.com/s/3Ed9lB9 ? Now its really applying each time, but with conditions on the screen reset of ‘woocommerce_cart_hash’ will work only one time …

    https://demo.pluginus.net/wptester/shop/ – I just made the test – storefront+woo+woocs only – all is fine as I applied https://clip2net.com/s/3Ed9lB9 (GET condition in code) AND request really works ONLY if currency is changed https://demo.pluginus.net/wptester/shop/?currency=USD

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Wrong cookie leads to Ajax request on every page’ is closed to new replies.