0) { return $id; } $page = get_page_by_path('epaggelmaties-spoudastes'); return $page ? (int) $page->ID : 0; } public static function membership_url() { $id = self::membership_page_id(); if ($id > 0) { $url = get_permalink($id); if ($url) { return (string) $url; } } return home_url(); } public function add_endpoint() { add_rewrite_endpoint(self::ENDPOINT, EP_ROOT | EP_PAGES); } public function query_vars($vars) { $vars[] = self::ENDPOINT; return $vars; } public function menu_items($items) { $logout = isset($items['customer-logout']) ? $items['customer-logout'] : null; if ($logout !== null) { unset($items['customer-logout']); } $items[self::ENDPOINT] = __('Professional account', 'ai-eshop-optimizer'); if ($logout !== null) { $items['customer-logout'] = $logout; } return $items; } public function wc_query_vars($vars) { $vars[self::ENDPOINT] = self::ENDPOINT; return $vars; } public function endpoint_title() { return __('Professional account', 'ai-eshop-optimizer'); } public function endpoint_content() { echo do_shortcode('[' . self::SHORTCODE . ']'); } public function maybe_flush_rules() { if (get_option(self::FLUSH_OPTION) === 'done') { return; } flush_rewrite_rules(false); update_option(self::FLUSH_OPTION, 'done', false); } public function enqueue_assets() { global $wp_query; if (is_admin() || empty($wp_query) || !isset($wp_query->query_vars[self::ENDPOINT])) { return; } $rel = 'assets/css/aieo-push.css'; $dir = defined('AIEO_RUNTIME_DIR') ? AIEO_RUNTIME_DIR : WP_PLUGIN_DIR . '/ai-eshop-optimizer-runtime/'; $uri = defined('AIEO_RUNTIME_URI') ? AIEO_RUNTIME_URI : plugins_url('ai-eshop-optimizer-runtime/'); $path = $dir . $rel; if (file_exists($path) && !wp_style_is('aieo-push-optin', 'enqueued')) { wp_enqueue_style('aieo-push-optin', $uri . $rel, array(), (string) filemtime($path)); } } public function shortcode() { if (!is_user_logged_in()) { $login_url = function_exists('wc_get_page_permalink') ? (string) wc_get_page_permalink('myaccount') : wp_login_url(); return '
' . sprintf( wp_kses( __('Sign in to see your professional account.', 'ai-eshop-optimizer'), array('a' => array('href' => array())) ), esc_url($login_url) ) . '
'; } $user = wp_get_current_user(); $pro_slugs = self::pro_role_slugs(); $active = !empty($pro_slugs) ? array_values(array_intersect((array) $user->roles, $pro_slugs)) : array(); return !empty($active) ? $this->render_pro($user, $active) : $this->render_non_pro(); } private function render_pro($user, $active) { $names = $this->role_display_names($active); $out = '' . esc_html__('You are registered as:', 'ai-eshop-optimizer') . ' ' . esc_html(implode(', ', $names)) . '
'; $out .= '' . esc_html__('Manage / change plan', 'ai-eshop-optimizer') . '
'; $out .= '' . esc_html__('Are you a professional? Join our professional programme for special prices, access to exclusive products and invitations to events.', 'ai-eshop-optimizer') . '
'; $out .= '' . esc_html__('Join the professional programme', 'ai-eshop-optimizer') . '
'; } $out .= '' . sprintf( esc_html__('You have saved %s thanks to your professional status.', 'ai-eshop-optimizer'), wp_kses_post(wc_price($savings)) ) . '
'; $out .= '' . sprintf( esc_html(_n( '%1$s product at a professional price, across %2$s orders.', '%1$s προϊόντα σε επαγγελματική τιμή, σε %2$s παραγγελίες.', $pro_lines, 'ai-eshop-optimizer' )), esc_html(number_format_i18n($pro_lines)), esc_html(number_format_i18n($orders)) ) . '
'; } else { $out .= '' . esc_html__('You have not saved anything yet — your purchases at professional prices will appear here.', 'ai-eshop-optimizer') . '
'; } $out .= '