W
W
WebforSelf2020-11-25 15:02:59
WordPress
WebforSelf, 2020-11-25 15:02:59

How to disable caching for Woocomerce random products?

Such a task, it is necessary that the goods that I display through the shortcode are not cached, but constantly take new ones.

I found such a function in the API

protected function get_transient_name() {
    $transient_name = 'wc_product_loop_' . md5( wp_json_encode( $this->query_args ) . $this->type );

    if ( 'rand' === $this->query_args['orderby'] ) {
      // When using rand, we'll cache a number of random queries and pull those to avoid querying rand on each page load.
      $rand_index      = wp_rand( 0, max( 1, absint( apply_filters( 'woocommerce_product_query_max_rand_cache_count', 5 ) ) ) );
      $transient_name .= $rand_index;
    }

    return $transient_name;
  }


You can somehow disable it through the filters so that the goods are collected randomly from all that are laid down by the shortcode.

[products attribute="stil" terms="Дизайнерский" orderby="rand" limit="8"]


That is, all goods (and there are 500 of them somewhere) will spin randomly. And now only a few blocks are static and change periodically.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebforSelf, 2020-11-25
@WebforSelf

Suddenly someone will come in handy, though the decision is not correct, because. will be overwritten during the update, it is necessary to take it out in the function
$rand_index = wp_rand( 0, max );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question