Forum Replies Created

Viewing 15 replies - 1 through 15 (of 31 total)
  • Thread Starter audriusexe

    (@audriusexe)

    Have you received my email?

    Thread Starter audriusexe

    (@audriusexe)

    “Using AJAX to show stock count and items in cart” – perfect idea.

    Still trying to find a solution for finding all products in a product group – I think leave at the moment till the first request from someone.

    I will also make woo caching a pro feature. – good, because this is the only cache plugin having normal Woo caching. Other caching Woo are WP Rocket, W3 Total Cache, WP Super Cache, WP Fastest Cache, but they require a lot of manual configuration and still will not work as this one.

    I’m interested in using this and some other plugins from atec in more pages than one, but let’s test this plugin in production first. I will write you an email with some other ideas.

    For now, I think you should delete this thread (if you can), because here is to much specific and interesting information. 🙂

    Thread Starter audriusexe

    (@audriusexe)

    Thank you for all your input.

    I have a personal interest here. If implementation is done, then now I’m ready to buy this plugin. Is there any Agency or similar plan for unlimited sites? 🙂 I’m not an agency, but I like to do ecom and will need such plugin all the time.

    Thread Starter audriusexe

    (@audriusexe)

    So i have to flush on add_action( ‘woocommerce_add_to_cart’, ‘wp_kama_woocommerce_add_to_cart_action’, 10, 6 );

    If ajax is used, then no need to flush. Cookie will be set correctly. For non ajax sites it can be flushed, but to identify that, another switch in plugin settings should be added? Flush on woocommerce_add_to_cart?

    Thread Starter audriusexe

    (@audriusexe)

    Cookie woocommerce_recently_viewed should be set on every product page view, but as product pages are cached, then I think handling of this cookie should be skipped. I personally do not use “last viewed products” blocks on any sites. But for these who want to have it, note in plugin should be added: Last viewed products will not work on cached pages and products. To have it you must implement custom dynamic loading solution for that. 🙂

    Thread Starter audriusexe

    (@audriusexe)

    The woocommerce_items_in_cart cookie will be set by ajax requests, but if there is no ajax, then I think it will handled by woo itself, because on $_GET[‘add-to-cart’]) || isset($_GET[‘remove_item’]) || isset($_REQUEST[‘update_cart’]) cache will be skipped anyway.

    Thread Starter audriusexe

    (@audriusexe)

    cookie wp_woocommerce_session is set on any first time interaction with any woocommerce element. Cart, product page, etc.

    So, if in cache plugin product caching is activated, then this cookie also can be set by cache plugin.

    if (!isset($_COOKIE[‘wp_woocommerce_session’])) {
    WC(); // Initialize WooCommerce
    $session_handler = new WC_Session_Handler();
    $session = $session_handler->init_session();
    $customer_id = $session_handler->generate_customer_id();
    $session_handler->set_customer_session_cookie(true);
    $session_handler->save_data();
    }

    Thread Starter audriusexe

    (@audriusexe)

    I think wc_session cookie can be set by caching plugin itself if visitor doesn’t has it yet.

    if (!isset($_COOKIE[‘wc_session’])) { setcookie(‘wc_session’, generate_session_id(), time() + 3600, ‘/’); }

    woocommerce_cart_hash is changing with every cart operation. It’s not a problem with ajax requests, but if ajax is not used, then specific cart requests should be skipped from cache.

    $woo_actions = [‘add-to-cart’, ‘remove_item’, ‘apply_coupon’, ‘remove_coupon’, ‘update_cart’];

    if (array_intersect(array_keys($_GET), $woo_actions)) {
    // no cache here
    }

    Thread Starter audriusexe

    (@audriusexe)

    What “Pages with personification features.” do you mean and how can i identify them?

    These are pages which write “Hello, Chris!”. Or when A/B testing is done without dynamic data loading. Such pages should be excluded from caching. Other caching plugins use exclude list by url fragments for that.

    Thread Starter audriusexe

    (@audriusexe)

    Is it possible to have
    if (class_exists(‘woocommerce’) && (is_cart() || is_checkout() || is_account_page() || (is_woocommerce() && !is_product() && !is_product_category())))

    And then when product cache is cleaned also clean categories cache of that product?

    Thread Starter audriusexe

    (@audriusexe)

    Checklist of what should be excluded from caching.

    Pages to always exclude from the cache:
    Shopping cart page
    Checkout page
    Login and registration pages
    My Account page

    Cookies to exclude from the cache:
    _wc_session
    woocommerce_cart_hash
    woocommerce_items_in_cart
    wp_woocommerce_session
    woocommerce_recently_viewed

    One more case. Pages with personification features. For these cases it would be good to have an exclude list in cache plugin settings. Most of the cache plugins have such option.

    Thread Starter audriusexe

    (@audriusexe)

    woocommerce_product_set_stock_status is executed when product changes a state between: instock, outofstock, onbackorder.

    If product has 7 items in stock, product state is instock.
    If one product is sold and now there are 6 items in stock, hook woocommerce_product_set_stock_status is not executed, because products state is still instock.
    When all products are sold and there is 0 items in stock, only then woocommerce_product_set_stock_status is executed, because product state has changed from instock into outofstock.

    It means that cache doesn’t need to be cleared all that time and this is good for performance.

    Default woo theme is not loading stock quantity using ajax. In such cases woocommerce_product_set_stock should be used to clear cache on every stock change.

    But there are a lot of plugins and themes which show the actual stock level by using ajax. In such cases to use woocommerce_product_set_stock_status would be much more effective. I personally have a project, where product can have +3500 variations. To load all of them as static values is not good. In such case we use ajax to get up-to-date information for the variation when it is selected. To clean the cache when stock for any of this variation changes and reload all the product because of that one variation stock change will not be effective. In such cases, better clean the product cache when stock status changes between instock and outofstock, onbackorder.

    Thread Starter audriusexe

    (@audriusexe)

    Product group is also a product, but it is made from other products. I never saw someone using it and I do not use it too, but it has relation to products. This is why I have added it here.

    Regarding translations you are right.

    Thread Starter audriusexe

    (@audriusexe)

    And the last type of cache to clear when clearing product cache. Translations. Get all product translations done with WPML.

    $current_product_id = get_the_ID();
    $element_type = apply_filters(‘wpml_element_type’, ‘product’);
    $trid = apply_filters(‘wpml_element_trid’, false, $current_product_id, $element_type);
    $translations = apply_filters(‘wpml_get_element_translations’, array(), $trid, $element_type);
    $related_products = array();

    foreach ($translations as $lang => $translation) {
    $product = wc_get_product($translation->element_id);
    if ($product) {
    $related = wc_get_related_products($product->get_id());
    $related_products[$lang] = $related;
    }
    }

    I think this is all relations for the product and caches to clean when cleaning product cache.

    • This reply was modified 1 year, 4 months ago by audriusexe.
    Thread Starter audriusexe

    (@audriusexe)

    Product can be part of the specific product type “Product group”. When clearing product cache, then all “product groups” cache also should be cleared.

    $args = array(
    ‘post_type’ => ‘product’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘product_type’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘grouped’
    )
    ),
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘_children’,
    ‘value’ => ‘”‘ . $product_id . ‘”‘,
    ‘compare’ => ‘LIKE’
    )
    )
    );

    $grouped_products = new WP_Query($args);

Viewing 15 replies - 1 through 15 (of 31 total)