• When the database cache is activated on W3 Total Cache, sometimes we have problems when saving a WooCommerce order and then immediately getting it from the database where not all details saved before are available on the newly gotten object.

    For example:

    
    //Get the order and update some meta on it
    $order = wc_get_order( 1234 );
    $order-> update_meta_data( 'some_field', 'some_data' );
    $order->save();
    
    //Let other developers do something to the order before working with it again
    $order = apply_filters( 'some_action_on_the_order', $order );
    
    //Get the order again (because other developers may have changed something on it) and work with it again
    $order = wc_get_order( 1234 );
    echo $order->get_meta( 'some_field' ); //We do not get 'some_data' if W3 Total cache database cache is active
    

    Anything we can do between saving the order and getting it again to make sure when we get it is completely updated?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @webdados

    Thank you for reaching out.
    Can you please share which caching method you are using for Database caching and if you are also using Object Chaching besides that?
    Thanks!

    I have the save problem. I am using “Disk” type.
    I ONLY have this problem when using Database cache. With Object Cache, I have no problem.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @miguelfspinto

    Thank you for your feedback.
    You should avoid using Database Cache and caching to disk and especially because of this kind of issue, The database is faster sometimes than disk caching, so you should consider using the Memory-based caching like Redis or Memcached for Database caching and Object Caching as well.
    Thanks!

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    @vmarko So what you’re saying is that “Database Cache and caching to disk” breaks websites? Maybe remove that option or warn users about it?

    My original question was if there’s something we can do to keep using this cache and not have this problem, like running a function to reset cache on that post?

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @webdados

    DB caching, when set to disk, can cause a slow website, however that depends on many things and of course how much the database is utilized?
    I understand your original question and can you please share the information on which caching method you are using for Database caching and if you are also using Object Caching besides that?

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    Exactly the same as @miguelfspinto
    It’s actually a website one of my plugins is installed that is run by him, and we found out this issue together debugging why updating meta on an order, saving it, then get it again from the database and the updated data is not there.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WooCommerce $order->save() and wc_get_order() problems with database cache’ is closed to new replies.