diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index 16fdb1a4d1a..e9e059463b5 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -780,6 +780,15 @@ CREATE TABLE {$wpdb->prefix}woocommerce_termmeta ( $tables[] = "{$wpdb->prefix}woocommerce_termmeta"; } + /** + * Filter the list of known WooCommerce tables. + * + * If WooCommerce plugins need to add new tables, they can inject them here. + * + * @param array $tables An array of WooCommerce-specific database table names. + */ + $tables = apply_filters( 'woocommerce_install_get_tables', $tables ); + return $tables; } diff --git a/tests/unit-tests/util/install.php b/tests/unit-tests/util/install.php index f323b26de7e..4ecb176fd40 100644 --- a/tests/unit-tests/util/install.php +++ b/tests/unit-tests/util/install.php @@ -125,4 +125,25 @@ class WC_Tests_Install extends WC_Unit_Test_Case { $this->assertEquals( $tables, WC_Install::get_tables() ); } + + /** + * Test - get tables should apply the woocommerce_install_get_tables filter. + */ + public function test_get_tables_enables_filter() { + $default = WC_Install::get_tables(); + $added = $this->append_table_to_get_tables( array() ); + + add_filter( 'woocommerce_install_get_tables', array( $this, 'append_table_to_get_tables' ) ); + + $this->assertEquals( $added, array_values( array_diff( WC_Install::get_tables(), $default ) ) ); + } + + /** + * Filter callback for test_get_tables_enables_filter(). + */ + public function append_table_to_get_tables( $tables ) { + $tables[] = 'some_table_name'; + + return $tables; + } }