template_path = WC_BOOTSTRAP_PATH . 'templates'; } /** * Register the template override with WordPress hooks. * * Must be called after the plugin's Template singleton is initialized * (plugin inits at 'init' priority 0). * * @return void */ public function register(): void { add_action( 'init', [ $this, 'override_template_paths' ], 20 ); } /** * Prepend the child theme's templates directory to the Twig loader. * * This makes Twig look in the child theme's templates/ first, * falling back to the plugin's templates/ if not found. * * @return void */ public function override_template_paths(): void { if ( ! class_exists( Template::class ) ) { return; } if ( ! is_dir( $this->template_path ) ) { return; } try { $twig = Template::get_instance()->get_twig(); $loader = $twig->getLoader(); if ( $loader instanceof FilesystemLoader ) { $loader->prependPath( $this->template_path ); } } catch ( \Exception $e ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( 'WooCommerce Bootstrap: Failed to register template override - ' . $e->getMessage() ); } } } }