array(), 'version' => filemtime( $script_path ), ); $script_url = plugins_url( $script_path, __FILE__ ); $script_asset['dependencies'][] = WC_ADMIN_APP; // Add WCA as a dependency to ensure it loads first. wp_register_script( 'woocommerce-admin-test-helper', $script_url, $script_asset['dependencies'], $script_asset['version'], true ); wp_enqueue_script( 'woocommerce-admin-test-helper' ); $css_file_version = filemtime( dirname( __FILE__ ) . '/build/index.css' ); wp_register_style( 'wp-components', plugins_url( 'dist/components/style.css', __FILE__ ), array(), $css_file_version ); wp_register_style( 'woocommerce-admin-test-helper', plugins_url( '/build/index.css', __FILE__ ), // Add any dependencies styles may have, such as wp-components. array( 'wp-components', ), $css_file_version ); wp_enqueue_style( 'woocommerce-admin-test-helper' ); } add_action( 'admin_enqueue_scripts', 'add_extension_register_script' ); add_action( 'before_woocommerce_init', function() { if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'product_block_editor', __FILE__, true ); } } ); /** * Simulate a WooCommerce error for remote logging testing. * * This function adds a filter to the 'woocommerce_template_path' hook * that throws an exception, then triggers the filter by calling WC()->template_path(). * * @throws Exception A simulated WooCommerce error for testing purposes. */ function simulate_woocommerce_error() { // Return if WooCommerce is not loaded. if ( ! function_exists( 'WC' ) || ! class_exists( 'WooCommerce' ) ) { return; } // Define a constant to prevent the error from being caught by the WP Error Handler. if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { define( 'WP_SANDBOX_SCRAPING', true ); } add_filter( 'woocommerce_template_path', function() { throw new Exception( 'Simulated WooCommerce error for remote logging test' ); } ); WC()->template_path(); } $simulate_error = get_option( 'wc_beta_tester_simulate_woocommerce_php_error', false ); if ( $simulate_error ) { delete_option( 'wc_beta_tester_simulate_woocommerce_php_error' ); if ( 'core' === $simulate_error ) { // Hook into the plugin_loaded action to simulate the error early before WP fully initializes. add_action( 'plugin_loaded', 'simulate_woocommerce_error' ); } elseif ( 'beta-tester' === $simulate_error ) { throw new Exception( 'Test PHP exception from WooCommerce Beta Tester' ); } } // Initialize the live branches feature. require_once dirname( __FILE__ ) . '/includes/class-wc-beta-tester-live-branches.php';