settings_hook = add_submenu_page( 'woocommerce', __( 'Customer Account', 'advanced-customer-account' ), __( 'Customer Account', 'advanced-customer-account' ), 'manage_woocommerce', 'aca-settings', array( $this, 'render_admin_page' ) ); } /** * Redirect legacy settings page if visited. */ public function check_legacy_settings_redirect() { global $pagenow; if ( 'options-general.php' === $pagenow && isset( $_GET['page'] ) && 'aca-settings' === $_GET['page'] ) { wp_safe_redirect( admin_url( 'admin.php?page=aca-settings' ) ); exit; } } /** * Add action links on plugins list page. * * @param array $links Existing plugin links. * @return array */ public function add_plugin_action_links( $links ) { $settings_link = sprintf( '%s', esc_url( admin_url( 'admin.php?page=aca-settings' ) ), __( 'Settings', 'advanced-customer-account' ) ); array_unshift( $links, $settings_link ); return $links; } /** * Enqueue admin scripts and styles for the settings page. * * @param string $hook Page hook suffix. */ public function enqueue_admin_assets( $hook ) { $is_settings_page = ( isset( $_GET['page'] ) && 'aca-settings' === $_GET['page'] ); if ( ! $is_settings_page && $hook !== $this->settings_hook && 'woocommerce_page_aca-settings' !== $hook ) { return; } $asset_file = ACA_PLUGIN_DIR . 'build/admin.asset.php'; if ( file_exists( $asset_file ) ) { $assets = include $asset_file; } else { $assets = array( 'dependencies' => array( 'wp-element', 'wp-components', 'wp-api-fetch', 'wp-i18n', 'wp-data', 'wp-hooks', 'wp-notices', ), 'version' => ACA_VERSION, ); } $dependencies = array_values( array_diff( $assets['dependencies'], array( 'react-jsx-runtime' ) ) ); if ( ! in_array( 'wp-element', $dependencies, true ) ) { $dependencies[] = 'wp-element'; } // Enqueue admin React app. wp_enqueue_script( 'aca-admin-app', ACA_PLUGIN_URL . 'build/admin.js', $dependencies, $assets['version'], true ); // Nonce middleware for api-fetch. wp_add_inline_script( 'wp-api-fetch', sprintf( 'wp.apiFetch.use( wp.apiFetch.createNonceMiddleware( "%s" ) );', wp_create_nonce( 'wp_rest' ) ), 'after' ); // Prepare initial settings and active coupons for instant rendering. $saved_settings = get_option( 'aca_settings', array() ); $defaults = array( 'primary_color' => '#5304c1', 'enable_dark_mode' => false, 'rewards_enabled' => true, 'rewards_type' => 'auto', 'rewards_target_orders' => 10, 'rewards_target_spend' => 250, 'rewards_discount_label' => '15% OFF', 'rewards_coupon_code' => 'VIP15', 'rewards_description' => __( 'Unlock our exclusive VIP Club discount with your orders!', 'advanced-customer-account' ), 'menu_items' => class_exists( 'ACA_Menu_API' ) ? ACA_Menu_API::get_merged_menu_items() : array(), ); $initial_settings = wp_parse_args( $saved_settings, $defaults ); $coupons_query = get_posts( array( 'post_type' => 'shop_coupon', 'post_status' => 'publish', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC', ) ); $initial_coupons = array(); foreach ( $coupons_query as $coupon_post ) { $coupon = new WC_Coupon( $coupon_post->ID ); $amount = $coupon->get_amount(); $discount_type = $coupon->get_discount_type(); $min_spend = (float) $coupon->get_minimum_amount(); $label = $coupon->get_code(); if ( 'percent' === $discount_type ) { $label .= ' (' . $amount . '% off)'; } elseif ( $amount > 0 && function_exists( 'wc_price' ) ) { $label .= ' (' . wp_strip_all_tags( wc_price( $amount ) ) . ' off)'; } $initial_coupons[] = array( 'code' => $coupon->get_code(), 'label' => $label, 'amount' => $amount, 'min_spend' => $min_spend, ); } // Localize configuration. wp_localize_script( 'aca-admin-app', 'acaAdminConfig', array( 'apiUrl' => esc_url_raw( rest_url( 'aca/v1/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'accountPageUrl' => function_exists( 'wc_get_page_permalink' ) ? wc_get_page_permalink( 'myaccount' ) : home_url( '/my-account/' ), 'shopUrl' => function_exists( 'wc_get_page_permalink' ) ? wc_get_page_permalink( 'shop' ) : home_url( '/shop/' ), 'version' => ACA_VERSION, 'settings' => $initial_settings, 'coupons' => $initial_coupons, 'currencySymbol' => html_entity_decode( get_woocommerce_currency_symbol() ), ) ); // Core WordPress components styling. wp_enqueue_style( 'wp-components' ); // Custom admin styling if compiled. $css_file = ACA_PLUGIN_DIR . 'build/admin.css'; if ( file_exists( $css_file ) ) { wp_enqueue_style( 'aca-admin-style', ACA_PLUGIN_URL . 'build/admin.css', array( 'wp-components' ), filemtime( $css_file ) ); } } /** * Render settings page wrapper. */ public function render_admin_page() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'advanced-customer-account' ) ); } ?>

[aca_my_account]' ); ?>