Add transient caching to product_loop

Closes #11708
This commit is contained in:
Mike Jolley 2016-08-18 13:19:57 +01:00
parent 5a740b7837
commit fb585e9633
1 changed files with 7 additions and 1 deletions

View File

@ -84,10 +84,16 @@ class WC_Shortcodes {
private static function product_loop( $query_args, $atts, $loop_name ) { private static function product_loop( $query_args, $atts, $loop_name ) {
global $woocommerce_loop; global $woocommerce_loop;
$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $query_args, $atts, $loop_name ) );
$columns = absint( $atts['columns'] ); $columns = absint( $atts['columns'] );
$woocommerce_loop['columns'] = $columns; $woocommerce_loop['columns'] = $columns;
$woocommerce_loop['name'] = $loop_name; $woocommerce_loop['name'] = $loop_name;
$transient_name = 'wc_loop_' . $loop_name . '_' . WC_Cache_Helper::get_transient_version( 'product_query' );
$products = get_transient( $transient_name );
if ( false === $products || ! is_a( $products, 'WP_Query' ) ) {
$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $query_args, $atts, $loop_name ) );
set_transient( $transient_name, $products, DAY_IN_SECONDS * 30 );
}
ob_start(); ob_start();