register( new WC_AddressZen_Blocks_Integration() ); } /** * Enqueue block assets on checkout pages as a fallback. * Only enqueues if the IntegrationInterface didn't already register scripts. */ public static function maybe_enqueue_block_assets() { if ( ! self::is_block_checkout() ) { return; } // Skip if the integration already enqueued the script if ( wp_script_is( 'addresszen-blocks-frontend', 'enqueued' ) ) { return; } require_once ADDRESSZEN_DIR . 'classes' . DIRECTORY_SEPARATOR . 'class-addresszen-blocks-integration.php'; $settings = WC_AddressZen_Blocks_Integration::build_settings(); if ( empty( $settings['enabled'] ) || empty( $settings['apiKey'] ) ) { return; } // Register and enqueue script $script_path = ADDRESSZEN_DIR . 'js/blocks/checkout-blocks-frontend.asset.php'; $script_asset = file_exists( $script_path ) ? require $script_path : array( 'dependencies' => array(), 'version' => ADDRESSZEN_VERSION ); wp_enqueue_script( 'addresszen-blocks-frontend', ADDRESSZEN_URL . 'js/blocks/checkout-blocks-frontend.js', $script_asset['dependencies'], $script_asset['version'], true ); // Pass settings via inline script (dual approach) wp_add_inline_script( 'addresszen-blocks-frontend', 'window.wcSettings = window.wcSettings || {};' . 'window.wcSettings["addresszen_data"] = ' . wp_json_encode( $settings ) . ';', 'before' ); // Enqueue styles wp_enqueue_style( 'addresszen-blocks-style', ADDRESSZEN_URL . 'css/addresszen.css', array(), ADDRESSZEN_VERSION ); } /** * Check if the current page uses WooCommerce block checkout. * * @return bool */ private static function is_block_checkout() { global $post; if ( ! $post ) { return false; } return has_block( 'woocommerce/checkout', $post ); } }