Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 686c787

Browse files
authored
Merge pull request #212 from woocommerce/add/clear-template-cache
add clear template cache tool
2 parents bd45d70 + f963210 commit 686c787

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ public function get_tools() {
167167
__( 'This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce-rest-api' )
168168
),
169169
),
170+
'clear_template_cache' => array(
171+
'name' => __( 'Clear template cache', 'woocommerce-rest-api' ),
172+
'button' => __( 'Clear', 'woocommerce-rest-api' ),
173+
'desc' => sprintf(
174+
'<strong class="red">%1$s</strong> %2$s',
175+
__( 'Note:', 'woocommerce-rest-api' ),
176+
__( 'This tool will empty the template cache.', 'woocommerce-rest-api' )
177+
),
178+
),
170179
'install_pages' => array(
171180
'name' => __( 'Create default WooCommerce pages', 'woocommerce-rest-api' ),
172181
'button' => __( 'Create pages', 'woocommerce-rest-api' ),
@@ -215,6 +224,10 @@ public function get_tools() {
215224
unset( $tools['regenerate_thumbnails'] );
216225
}
217226

227+
if ( ! function_exists( 'wc_clear_template_cache' ) ) {
228+
unset( $tools['clear_template_cache'] );
229+
}
230+
218231
return apply_filters( 'woocommerce_debug_tools', $tools );
219232
}
220233

@@ -547,6 +560,16 @@ public function execute_tool( $tool ) {
547560
$message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce-rest-api' );
548561
break;
549562

563+
case 'clear_template_cache':
564+
if ( function_exists( 'wc_clear_template_cache' ) ) {
565+
wc_clear_template_cache();
566+
$message = __( 'Template cache cleared.', 'woocommerce-rest-api' );
567+
} else {
568+
$message = __( 'The active version of WooCommerce does not support template cache clearing.', 'woocommerce-rest-api' );
569+
$ran = false;
570+
}
571+
break;
572+
550573
case 'verify_db_tables':
551574
if ( ! method_exists( 'WC_Install', 'verify_base_tables' ) ) {
552575
$message = __( 'You need WooCommerce 4.2 or newer to run this tool.', 'woocommerce-rest-api' );

0 commit comments

Comments
 (0)