boot_data() ) . ';', 'before' ); } /** * Data handed to the React app on load. * * @return array */ private function boot_data(): array { return array( 'restRoot' => esc_url_raw( rest_url( 'profit-engine/v1' ) ), 'restNonce' => wp_create_nonce( 'wp_rest' ), 'adminUrl' => esc_url_raw( admin_url( 'admin.php?page=profit-engine-dashboard' ) ), 'printBase' => esc_url_raw( admin_url( 'admin-post.php' ) ), 'printNonce' => wp_create_nonce( 'profit_engine_print_po' ), 'currency' => array( 'code' => function_exists( 'get_woocommerce_currency' ) ? get_woocommerce_currency() : 'USD', 'symbol' => function_exists( 'get_woocommerce_currency_symbol' ) ? html_entity_decode( get_woocommerce_currency_symbol() ) : '$', 'decimals' => function_exists( 'wc_get_price_decimals' ) ? wc_get_price_decimals() : 2, // Match the store's own price format (WooCommerce → Settings → Currency options). 'position' => (string) get_option( 'woocommerce_currency_pos', 'left' ), 'thousand' => function_exists( 'wc_get_price_thousand_separator' ) ? wc_get_price_thousand_separator() : ',', 'decimal' => function_exists( 'wc_get_price_decimal_separator' ) ? wc_get_price_decimal_separator() : '.', ), 'currencies' => $this->currency_options(), 'orderStatuses' => $this->order_status_options(), 'logoUrl' => esc_url_raw( PROFIT_ENGINE_PLUGIN_URL . 'assets/images/profitengine-logo.svg?ver=' . PROFIT_ENGINE_VERSION ), 'canManage' => Capabilities::current_user_can(), 'version' => PROFIT_ENGINE_VERSION, ); } /** * WooCommerce order statuses as [{ slug, label }] (wc- prefix stripped). * * @return array */ private function order_status_options(): array { if ( ! function_exists( 'wc_get_order_statuses' ) ) { return array(); } $options = array(); foreach ( wc_get_order_statuses() as $slug => $label ) { $options[] = array( 'slug' => (string) preg_replace( '/^wc-/', '', (string) $slug ), 'label' => (string) $label, ); } return $options; } /** * WooCommerce's currency list as [{ code, label }] for select controls. * * @return array */ private function currency_options(): array { if ( ! function_exists( 'get_woocommerce_currencies' ) ) { return array( array( 'code' => 'USD', 'label' => 'USD — US Dollar', ), ); } $options = array(); foreach ( get_woocommerce_currencies() as $code => $name ) { $symbol = html_entity_decode( get_woocommerce_currency_symbol( $code ) ); $options[] = array( 'code' => $code, 'label' => sprintf( '%s — %s (%s)', $code, $name, $symbol ), ); } return $options; } /** * Notice shown when the JS bundle has not been built. */ public function render_build_missing_notice(): void { echo '

'; echo '' . esc_html__( 'ProfitEngine', 'profit-engine' ) . ' — '; echo esc_html__( 'The admin interface has not been built yet. Run "npm install && npm run build" in the plugin directory.', 'profit-engine' ); echo '

'; } }