'#c0a37b', 'side_cart_card_border_hover' => '#a88a63', 'side_cart_accent_color' => '#c0a37b', 'side_cart_reco_title_color' => '#c0a37b', 'side_cart_mbar_bg' => '#f46767', 'side_cart_mbar_icon' => '#ffffff', 'side_cart_mbar_icon_active' => '#f46767', 'side_cart_mbar_badge_bg' => '#1f2937', 'side_cart_mbar_badge_fg' => '#ffffff', 'side_cart_btn_cart_bg' => '#e9e6e2', 'side_cart_btn_cart_color' => '#1a1a1a', 'side_cart_btn_cart_border_color' => '#e9e6e2', 'side_cart_btn_checkout_bg' => '#c0a37b', 'side_cart_btn_checkout_color' => '#ffffff', 'side_cart_btn_checkout_border_color' => '#c0a37b', 'side_cart_btn_save_bg' => '#e9e6e2', 'side_cart_btn_save_color' => '#1a1a1a', 'side_cart_btn_save_border_color' => '#e9e6e2', ); const RETIRED_SELECTED = array( 'bg' => '#ffffff', 'fg' => '#1f2937', 'bc' => '#ffffff', ); public static function retired_colour( $key ) { $key = (string) $key; if ( isset( self::RETIRED_COLOURS[ $key ] ) ) { return self::RETIRED_COLOURS[ $key ]; } if ( preg_match( '/^side_cart_mbar_[a-z]+_sel_(bg|fg|bc)$/', $key, $m ) ) { return self::RETIRED_SELECTED[ $m[1] ]; } return ''; } public static function colour( $key, $value = null ) { $v = (string) sanitize_hex_color( trim( (string) ( null === $value ? self::setting( $key, '' ) : $value ) ) ); $old = self::retired_colour( $key ); return ( '' !== $v && ( '' === $old || 0 !== strcasecmp( $v, $old ) ) ) ? $v : ''; } private static function module_enabled( $id ) { if ( class_exists( 'AIEO_DMM_Settings' ) ) { return AIEO_DMM_Settings::is_module_enabled( $id ); } return true; } private static function asset_dir() { return trailingslashit( dirname( __DIR__ ) ); } private static function asset_uri() { return trailingslashit( dirname( plugins_url( '', __FILE__ ) ) ); } private function render_cart_items_html() { if ( class_exists( 'AIEO_Runtime_Side_Cart' ) ) { return (string) AIEO_Runtime_Side_Cart::instance()->render_cart_items(); } if ( class_exists( 'AIEO_DMM_Side_Cart' ) ) { return (string) ( new AIEO_DMM_Side_Cart() )->render_cart_items(); } return ''; } public function register_display() { if ( ! self::module_enabled( 'side_cart' ) && ! self::setting( 'side_cart_enabled', false ) ) { return; } add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'wp_footer', array( $this, 'render_on_footer' ), 20 ); add_filter( 'rooster/bottom_bar/plugin_active', array( $this, 'filter_bottom_bar_active' ) ); add_filter( 'render_block_woocommerce/product-button', array( __CLASS__, 'without_view_cart' ) ); if ( $this->chat_slot_enabled() ) { add_filter( 'pre_option_aieo_chat_floating_enabled', array( $this, 'filter_force_chat_floating_on' ) ); add_action( 'wp_footer', array( $this, 'render_chat_overrides_style' ), 1000 ); } if ( self::setting( 'side_cart_quick_view_enabled', false ) ) { add_action( 'woocommerce_after_shop_loop_item', array( $this, 'render_archive_quick_view_trigger' ), 12 ); if ( class_exists( 'AIEO_Theme_Adapters' ) && method_exists( 'AIEO_Theme_Adapters', 'draw' ) ) { AIEO_Theme_Adapters::draw( 'quick_view', 'woocommerce_after_shop_loop_item' ); } } } public static function bar_items_catalog() { $items = array( array('slug' => 'nav', 'label' => __('Navigator (categories)', 'ai-eshop-optimizer'), 'enabled' => true), array('slug' => 'search', 'label' => __('Search (FiboSearch)', 'ai-eshop-optimizer'), 'enabled' => true), array('slug' => 'chat', 'label' => __('AI Chat', 'ai-eshop-optimizer'), 'enabled' => false), array('slug' => 'consent','label' => __('Cookie settings', 'ai-eshop-optimizer'), 'enabled' => self::consent_item_default()), array('slug' => 'cart', 'label' => __('Cart (side-cart trigger)','ai-eshop-optimizer'), 'enabled' => true), ); $added = apply_filters( 'aieo_side_cart_bar_items_catalog', $items ); $out = array(); $seen = array(); foreach ( is_array( $added ) ? $added : $items as $item ) { $slug = is_array( $item ) ? sanitize_key( (string) ( $item['slug'] ?? '' ) ) : ''; if ( '' === $slug || isset( $seen[ $slug ] ) ) { continue; } $seen[ $slug ] = true; $out[] = array( 'slug' => $slug, 'label' => (string) ( $item['label'] ?? $slug ), 'enabled' => ! empty( $item['enabled'] ) ); } return $out; } public static function discounts_html() { if ( ! function_exists( 'WC' ) || ! WC()->cart ) { return ''; } $out = ''; foreach ( WC()->cart->get_coupons() as $code => $coupon ) { $amount = (float) WC()->cart->get_coupon_discount_amount( $code, WC()->cart->display_cart_ex_tax ); $out .= '
' . esc_html( sprintf( __( 'Coupon: %s', 'ai-eshop-optimizer' ), wc_format_coupon_code( $code ) ) ) . '' . wp_kses_post( wc_price( -1 * $amount ) ) . '
'; } return $out; } public static function consent_banner_in_charge() { if ( class_exists( 'AIEO_Consent' ) && 'yes' === AIEO_Consent::settings()['enabled'] ) { return true; } return function_exists( 'rooster_setting' ) && 'theme' === rooster_setting( 'general', 'consent_banner', 'theme' ); } private static function consent_item_default() { return class_exists( 'AIEO_Theme_Contracts' ) && AIEO_Theme_Contracts::declares( 'C11' ) && self::consent_banner_in_charge(); } public static function consent_button_active() { if ( ! self::module_enabled( 'side_cart' ) && ! self::setting( 'side_cart_enabled', false ) ) { return false; } $saved = self::setting( 'side_cart_bar_items', null ); if ( is_array( $saved ) ) { foreach ( $saved as $row ) { if ( is_array( $row ) && isset( $row['slug'] ) && 'consent' === $row['slug'] ) { return ! empty( $row['enabled'] ); } } } return self::consent_item_default(); } public function resolve_bar_items_config() { $catalog = self::bar_items_catalog(); $by_slug = array(); foreach ($catalog as $g) { $by_slug[$g['slug']] = $g; } $saved = self::setting('side_cart_bar_items', null); if (!is_array($saved)) { $saved = array(); } $resolved = array(); $seen = array(); foreach ($saved as $row) { if (!is_array($row) || empty($row['slug'])) { continue; } $slug = sanitize_key($row['slug']); if (!isset($by_slug[$slug]) || isset($seen[$slug])) { continue; } $resolved[] = array( 'slug' => $slug, 'label' => $by_slug[$slug]['label'], 'enabled' => isset($row['enabled']) ? (bool) $row['enabled'] : (bool) $by_slug[$slug]['enabled'], ); $seen[$slug] = true; } foreach ($catalog as $g) { if (isset($seen[$g['slug']])) { continue; } $resolved[] = array( 'slug' => $g['slug'], 'label' => $g['label'], 'enabled' => (bool) $g['enabled'], ); } if ( ! self::cart_here() || self::strip_cart_in_words() ) { foreach ( $resolved as $k => $row ) { if ( 'cart' === $row['slug'] ) { $resolved[ $k ]['enabled'] = false; } } } elseif ( self::phone_lone_cart() ) { foreach ( $resolved as $k => $row ) { if ( 'cart' !== $row['slug'] ) { $resolved[ $k ]['enabled'] = false; } } } return $resolved; } private static function strip_cart_in_words() { if ( is_admin() || ! self::theme_c11() || ! function_exists( 'rooster_device_class' ) || 'mobile' !== rooster_device_class() ) { return false; } if ( ! function_exists( 'rooster_header_variant' ) || 'strip' !== (string) rooster_header_variant() ) { return false; } $setting = function_exists( 'rooster_setting' ) ? 'rooster_setting' : ''; $aside = false; if ( '' !== $setting ) { $words = 'words' === (string) $setting( 'design', 'header_icons', 'lucide' ); foreach ( (array) $setting( 'design', 'header_actions', array() ) as $entry ) { $action = is_array( $entry ) ? (string) ( $entry['action'] ?? '' ) : (string) $entry; if ( 'cart' === $action ) { $aside = $words || ( is_array( $entry ) && ! empty( $entry['text'] ) ); break; } } } return (bool) apply_filters( 'aieo_floating_cart_aside', $aside ); } private static function cart_here() { if ( is_admin() ) { return true; } $academy = class_exists( 'Rooster\Core\Blocks' ) && method_exists( 'Rooster\Core\Blocks', 'academy_page' ) && \Rooster\Core\Blocks::academy_page(); $theme = (bool) apply_filters( 'rooster/show_cart_icons', true ); return $academy ? $theme : ( $theme || self::store_page() ); } private static function store_page() { return ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) || ( function_exists( 'is_cart' ) && is_cart() ); } private static function phone_lone_cart() { return self::theme_header_on_phones() && ! self::quiet_page() && self::cart_here() && class_exists( 'Rooster\Core\Blocks' ) && method_exists( 'Rooster\Core\Blocks', 'header_cart' ) && ! \Rooster\Core\Blocks::header_cart(); } private function bar_has_items() { foreach ( $this->resolve_bar_items_config() as $item ) { if ( empty( $item['enabled'] ) ) { continue; } if ( 'consent' === $item['slug'] && ! ( class_exists( 'AIEO_Consent' ) && 'yes' === AIEO_Consent::settings()['reopen_enabled'] && self::consent_banner_in_charge() ) ) { continue; } return true; } return false; } public function resolve_chat_desktop_position() { $val = (string) self::setting('side_cart_chat_desktop_position', 'left'); return in_array($val, array('left', 'above'), true) ? $val : 'left'; } public function filter_bottom_bar_active( $active ) { if ( $active ) { return true; } if ( is_admin() || self::no_bar_here() || ! $this->bar_has_items() ) { return false; } $mbar = $this->resolve_mobile_bar_style(); return empty( $mbar['is_bubble'] ); } private static function no_bar_here() { return self::quiet_page() || ( self::theme_header_on_phones() && ! self::phone_lone_cart() ); } private static function quiet_page() { return ( function_exists( 'is_checkout' ) && is_checkout() && ! ( function_exists( 'is_wc_endpoint_url' ) && is_wc_endpoint_url( 'order-received' ) ) ) || self::focus_page(); } private static function focus_page() { return function_exists( 'is_singular' ) && is_singular() && 'template-focus' === get_page_template_slug( get_queried_object_id() ); } private static function theme_header_on_phones() { if ( ! self::theme_c11() || ! function_exists( 'rooster_device_class' ) || 'mobile' !== rooster_device_class() ) { return false; } $setting = function_exists( 'rooster_setting' ) ? 'rooster_setting' : ( function_exists( 'roosterx_setting' ) ? 'roosterx_setting' : '' ); return '' !== $setting && 'bottom' !== $setting( 'general', 'phone_nav', 'top' ); } public static function palette_class( $role ) { static $theme = null; if ( null === $theme ) { $theme = function_exists( 'rooster_design_authority' ) && 'theme' === rooster_design_authority(); } if ( ! $theme ) { return ''; } $roles = array( 'surface' => 'has-bg-background-color has-fg-color', 'text' => 'has-fg-color', ); return isset( $roles[ $role ] ) ? ' ' . $roles[ $role ] : ''; } public static function theme_c11() { return class_exists( 'AIEO_Theme_Contracts' ) && AIEO_Theme_Contracts::declares( 'C11' ) && ( function_exists( 'rooster_icon' ) || function_exists( 'roosterx_icon' ) ); } public static function foot_buttons( $settings = null ) { $get = static function ( $key, $default ) use ( $settings ) { if ( is_array( $settings ) ) { return array_key_exists( $key, $settings ) ? $settings[ $key ] : $default; } return self::setting( $key, $default ); }; if ( ! $get( 'side_cart_foot_chosen', false ) ) { return array( 'cart' => false, 'save' => true ); } return array( 'cart' => (bool) $get( 'side_cart_show_cart_btn', false ), 'save' => (bool) $get( 'side_cart_show_save_btn', true ), ); } public static function save_cart_script() { if ( ! class_exists( 'AIEO_Carts_Frontend' ) || ! method_exists( 'AIEO_Carts_Frontend', 'side_cart_script' ) ) { return null; } $carts = AIEO_Carts_Frontend::instance(); return $carts->show_in_sidecart() ? $carts->side_cart_script() : null; } public static function without_view_cart( $content ) { $content = (string) $content; if ( false === strpos( $content, 'state.displayViewCart' ) ) { return $content; } $without = preg_replace( '#]*\bdata-wp-bind--hidden="!state\.displayViewCart"[^>]*>\s*]*>.*?\s*#s', '', $content, 1 ); return null === $without ? $content : $without; } public static function hide_zero() { return (bool) self::setting( 'side_cart_hide_zero', true ); } public static function trigger_count_text( $count ) { $count = (int) $count; return ( $count > 0 || ! self::hide_zero() ) ? (string) $count : ''; } public static function look() { return class_exists( 'AIEO_Favourites' ) && AIEO_Favourites::theme_look(); } private static function line_variant( array $item ) { $chosen = ( isset( $item['variation'] ) && is_array( $item['variation'] ) ) ? $item['variation'] : array(); $values = array(); foreach ( $chosen as $attribute => $value ) { $value = is_scalar( $value ) ? trim( (string) $value ) : ''; if ( '' === $value ) { continue; } $taxonomy = (string) $attribute; if ( 0 === strpos( $taxonomy, 'attribute_' ) ) { $taxonomy = substr( $taxonomy, 10 ); } $term = taxonomy_exists( $taxonomy ) ? get_term_by( 'slug', $value, $taxonomy ) : false; $values[] = ( $term && ! is_wp_error( $term ) ) ? (string) $term->name : rawurldecode( $value ); } return implode( ' · ', $values ); } public static function line_permalink( $product, array $item = array(), $key = '' ) { if ( ! is_a( $product, 'WC_Product' ) ) { return ''; } $shown = (bool) $product->is_visible(); if ( ! $shown && empty( $item['_aieo_dmm_gift_offer_id'] ) ) { $parent = (int) $product->get_parent_id(); $shown = 'publish' === get_post_status( (int) $product->get_id() ) && ( ! $parent || 'publish' === get_post_status( $parent ) ); } $url = $shown ? (string) $product->get_permalink( $item ) : ''; return (string) apply_filters( 'woocommerce_cart_item_permalink', $url, $item, (string) $key ); } public static function bag_lines_html( array $cart, $remove_class = 'aieo-remove' ) { ob_start(); ?> self::colour("side_cart_mbar_{$slug}_sel_bg") ?: 'var(--wp--preset--color--bg,var(--wp--preset--color--base,Canvas))', 'fg' => self::colour("side_cart_mbar_{$slug}_sel_fg") ?: 'var(--wp--preset--color--fg,CanvasText)', 'bc' => self::colour("side_cart_mbar_{$slug}_sel_bc") ?: 'var(--wp--preset--color--bg,var(--wp--preset--color--base,Canvas))', ); } $items = $this->resolve_bar_items_config(); $enabled = array_values(array_filter($items, function ($i) { return !empty($i['enabled']); })); $only_cart = (count($enabled) === 1 && $enabled[0]['slug'] === 'cart'); $is_bubble = ($only_cart && ($bubble_on || self::phone_lone_cart())); $is_single = (count($enabled) === 1 && !$is_bubble); return array( 'bg' => $bg_out, 'icon' => $ico, 'icon_active' => $ico_active, 'badge_bg' => $bbg, 'badge_fg' => $bfg, 'backdrop' => $backdrop, 'sel_on' => $sel_on, 'sel' => $sel, 'height_css' => $is_bubble ? '0px' : ( ( $c11 && ! $custom ) ? 'calc(56px + env(safe-area-inset-bottom, 0px))' : $height . 'px' ), 'c11' => $c11, 'is_bubble' => $is_bubble, 'is_single' => $is_single, 'justify' => $is_single ? 'center' : 'space-between', 'page' => $page, ); } private function chat_slot_enabled() { $saved = self::setting('side_cart_bar_items', null); foreach (is_array($saved) ? $saved : array() as $row) { if (is_array($row) && !empty($row['slug']) && sanitize_key($row['slug']) === 'chat') { return !empty($row['enabled']); } } return false; } public function filter_force_chat_floating_on() { return '1'; } public function render_chat_overrides_style() { $css_path = self::asset_dir() . 'assets/css/aieo-chat-overrides.css'; if ( ! file_exists( $css_path ) ) { return; } $url = self::asset_uri() . 'assets/css/aieo-chat-overrides.css?ver=' . filemtime( $css_path ); echo '' . "\n"; } private function mbar_vars_css() { if (is_admin() || !function_exists('WC') || !WC()->cart) { return ''; } if (class_exists('AIEO_Catalogue_Mode') && AIEO_Catalogue_Mode::cart_off()) { return ''; } $mbar = $this->resolve_mobile_bar_style(); $no_bar = self::no_bar_here() || ! $this->bar_has_items(); if ( $no_bar ) { $mbar['height_css'] = '0px'; } $css = ':root{--aieo-mbar-bg:' . $mbar['bg'] . ';--aieo-mbar-icon:' . $mbar['icon'] . ';--aieo-mbar-badge-bg:' . $mbar['badge_bg'] . ';--aieo-mbar-badge-fg:' . $mbar['badge_fg'] . ';--aieo-mbar-height:' . $mbar['height_css'] . ';--aieo-mbar-backdrop:' . $mbar['backdrop'] . ';}'; if ( ! $mbar['is_bubble'] && ! $no_bar && ! empty( $mbar['c11'] ) ) { $css .= '@media(max-width:720px){body{--rooster-fab-offset:var(--aieo-mbar-height)}}'; } if ( $mbar['is_bubble'] || $no_bar ) { $css .= '@media(max-width:720px){body{padding-bottom:0!important}}'; } if ( ! $mbar['is_bubble'] && ! $no_bar && '' !== (string) ( $mbar['page'] ?? '' ) ) { $css .= '@container style(--wp--custom--rooster--bar--ground: page){.aieo-sc-floating-shell:not(.aieo-sc-shell--bubble){' . $mbar['page'] . '}}'; } return $css; } public function render_on_footer() { if (is_admin()) { return; } if (!function_exists('WC') || !WC()->cart) { return; } if (class_exists('AIEO_Catalogue_Mode') && AIEO_Catalogue_Mode::cart_off()) { return; } $count = (int) WC()->cart->get_cart_contents_count(); $subtotal = (string) WC()->cart->get_cart_subtotal(); $look = self::look(); $fs = $this->get_free_shipping_settings(); $fs_bar = class_exists('AIEO_DMM_Free_Shipping_Bar') ? (method_exists('AIEO_DMM_Free_Shipping_Bar', 'cart_figures') ? AIEO_DMM_Free_Shipping_Bar::cart_figures() : AIEO_DMM_Free_Shipping_Bar::figures()) : null; $thresh = null !== $fs_bar ? $fs_bar['threshold'] : (float) ($fs['free_shipping_threshold'] ?? 0); $raw = null !== $fs_bar ? $fs_bar['done'] : $this->get_cart_subtotal_raw(); $remaining = max(0, $thresh - $raw); $fs_rule = ( $count > 0 && class_exists( 'AIEO_DMM_Free_Shipping_Rules' ) ) ? AIEO_DMM_Free_Shipping_Rules::cart_freed_words() : ''; $nonce = wp_create_nonce('aieo_side_cart'); $border_enabled = (bool) self::setting('side_cart_card_border_enabled', true); $border_color = self::colour('side_cart_card_border_color'); $border_hover = self::colour('side_cart_card_border_hover'); if ( '' === $border_color ) { $border_color = 'var(--wp--preset--color--line, color-mix(in srgb, currentColor 16%, transparent))'; } if ( '' === $border_hover ) { $border_hover = 'var(--wp--preset--color--fg, currentColor)'; } $border_width = $border_enabled ? '1px' : '0'; $root_style = sprintf( '--aieo-card-border-width: %s; --aieo-card-border-color: %s; --aieo-card-border-hover: %s;', $border_width, esc_attr($border_color), esc_attr($border_hover) ); $mbar = $this->resolve_mobile_bar_style(); $no_bar = self::no_bar_here() || ! $this->bar_has_items(); $bar_items = array(); $progress_class = 'glass' === (string) self::setting('side_cart_progress_style', 'line') ? ' aieo-sc-pt-glass' : ''; $reco_off = function_exists( 'rooster_design_authority' ) && 'theme' === rooster_design_authority(); if ( $reco_off ) { $progress_class .= ' is-reco-off'; } ?>
data-fs-done="" data-currency-symbol="" data-currency-pos="" data-decimal-sep="" data-thousand-sep="" data-price-decimals="" data-msg-initial="" data-msg-progress="" data-msg-success="" data-fs-rule="" style="">
resolve_bar_items_config(); $chat_desk_pos = $this->resolve_chat_desktop_position(); $c11_icon = function ( $slug ) use ( $mbar ) { return ! empty( $mbar['c11'] ) ? (string) ( function_exists( 'rooster_icon' ) ? 'rooster_icon' : 'roosterx_icon' )( $slug ) : ''; }; foreach ( $bar_items as $item ) : if ( empty( $item['enabled'] ) ) { continue; } if ( $item['slug'] === 'consent' && ! ( class_exists( 'AIEO_Consent' ) && 'yes' === AIEO_Consent::settings()['reopen_enabled'] && self::consent_banner_in_charge() ) ) { continue; } switch ( $item['slug'] ) { case 'nav': ?> ! empty( $mbar['c11'] ) ) ); break; } endforeach; ?>
get_id(); if ($pid <= 0) { return; } $label = $this->label('side_cart_quick_view_label', __('Discover it', 'ai-eshop-optimizer')); echo ''; } public function enqueue_assets() { if (is_admin()) { return; } $bar_js = self::asset_dir() . 'assets/js/aieo-side-cart-bar.js'; if (file_exists($bar_js)) { wp_register_script('aieo-side-cart-bar', self::asset_uri() . 'assets/js/aieo-side-cart-bar.js', array(), (string) filemtime($bar_js), array('in_footer' => true, 'strategy' => 'defer')); wp_add_inline_script('aieo-side-cart-bar', 'window.aieoScBar = ' . wp_json_encode($this->resolve_mobile_bar_style()) . ';', 'before'); wp_enqueue_script('aieo-side-cart-bar'); } $css_path = self::asset_dir() . 'assets/css/aieo-side-cart.css'; $css_ver = file_exists($css_path) ? (string) filemtime($css_path) : AIEO_VERSION; wp_enqueue_style( 'aieo-side-cart', self::asset_uri() . 'assets/css/aieo-side-cart.css', array(), $css_ver ); $mbar_vars = $this->mbar_vars_css(); if ('' !== $mbar_vars) { wp_add_inline_style('aieo-side-cart', $mbar_vars); } $btn_css = $this->build_action_button_css(); if ($btn_css !== '') { wp_add_inline_style('aieo-side-cart', $btn_css); } $js_path = self::asset_dir() . 'assets/js/aieo-side-cart.js'; $js_ver = file_exists($js_path) ? (string) filemtime($js_path) : AIEO_VERSION; $iapi_on = method_exists('AIEO_DMM', 'is_iapi_enabled') && AIEO_DMM::is_iapi_enabled('side_cart'); if ($iapi_on && defined('AIEO_RUNTIME_DIR') && file_exists(AIEO_RUNTIME_DIR . 'assets/js/aieo-side-cart-iapi.js') ) { wp_register_script_module( '@aieo/side-cart-iapi', AIEO_Asset_Min::module_src(AIEO_RUNTIME_DIR . 'assets/js/aieo-side-cart-iapi.js', AIEO_RUNTIME_URI . 'assets/js/aieo-side-cart-iapi.js'), array('@wordpress/interactivity', '@aieo/iapi-bootstrap'), (string) filemtime(AIEO_RUNTIME_DIR . 'assets/js/aieo-side-cart-iapi.js'), array( 'fetchpriority' => 'low' ) ); wp_enqueue_script_module('@aieo/side-cart-iapi'); } else { wp_enqueue_script( 'aieo-side-cart', self::asset_uri() . 'assets/js/aieo-side-cart.js', array('jquery', 'wp-i18n'), $js_ver, array('in_footer' => true, 'strategy' => 'defer') ); } $aieo_sc_sheet = static function ($rel) { if (class_exists('AIEO_Asset_Min') && method_exists('AIEO_Asset_Min', 'layered') && AIEO_Asset_Min::layered()) { $layer_rel = preg_replace('/\.css$/', '.layer.css', $rel); if (file_exists(self::asset_dir() . $layer_rel)) { $rel = $layer_rel; } } $src = self::asset_dir() . $rel; $min_rel = preg_replace('/\.css$/', '.min.css', $rel); $min = self::asset_dir() . $min_rel; $has_src = file_exists($src); $has_min = file_exists($min); if (!$has_src && !$has_min) { return ''; } $debug = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG; $use_min = $has_min && (!$has_src || (!$debug && filemtime($min) >= filemtime($src))); return add_query_arg('ver', (string) filemtime($has_src ? $src : $min), self::asset_uri() . ($use_min ? $min_rel : $rel)); }; $contents_css_url = $aieo_sc_sheet('assets/css/aieo-side-cart-contents.css'); $ratings_css_url = $aieo_sc_sheet('assets/css/aieo-rating-stars.css'); $wishlist_css_url = $aieo_sc_sheet('assets/css/aieo-wishlist-heart.css'); $side_cart_data = array( 'ajaxurl' => admin_url('admin-ajax.php'), 'contentsCss' => $contents_css_url, 'storeCartUrl' => rest_url('wc/store/v1/cart'), 'cartUrl' => function_exists('wc_get_cart_url') ? wc_get_cart_url() : '', 'saveCart' => self::save_cart_script(), 'ratingsCss' => $ratings_css_url, 'wishlistCss' => $wishlist_css_url, 'debounce' => 500, 'nonce' => wp_create_nonce('aieo_side_cart'), 'recommendationsNonce' => wp_create_nonce('aieo_recommendations'), 'openOnAdd' => (bool) self::setting('side_cart_open_on_add', false), 'rowsQty' => (bool) self::setting('side_cart_rows_qty', false), 'hideZero' => self::hide_zero(), 'favEnabledTypes' => class_exists('AIEO_Wishlist') ? AIEO_Wishlist::enabled_types_list() : null, 'miniList' => self::look(), 'miniCss' => class_exists( 'AIEO_Favourites' ) ? AIEO_Favourites::asset_url( 'assets/css/aieo-mini-list.css' ) : '', 'miniJs' => class_exists( 'AIEO_Favourites' ) ? AIEO_Favourites::asset_url( 'assets/js/aieo-mini-list.js' ) : '', 'miniAction' => class_exists( 'AIEO_Favourites' ) ? AIEO_Favourites::ACTION : '', 'miniNonce' => wp_create_nonce( 'aieo_wishlist' ), 'i18n' => array( 'emptyBag' => __('Your bag is empty.', 'ai-eshop-optimizer'), 'maylikeDot' => __('Suggestion %d', 'ai-eshop-optimizer'), 'addToBag' => $this->label('side_cart_btn_addbag', __('Add to bag', 'ai-eshop-optimizer')), 'rvEmpty' => $this->label('side_cart_rv_empty', __('No recently viewed products.', 'ai-eshop-optimizer')), 'qvViewProduct' => $this->label('side_cart_qv_view_product', __('View product details', 'ai-eshop-optimizer')), 'rvAtc' => $this->label('side_cart_rv_atc', __('Add to bag', 'ai-eshop-optimizer')), 'favEmpty' => $this->label('side_cart_fav_empty', __('No favorites yet.', 'ai-eshop-optimizer')), 'favBrandsTitle' => $this->label('side_cart_fav_brands_title', __('Following', 'ai-eshop-optimizer')), 'favBrandProducts'=> $this->label('side_cart_fav_brand_products', __('products', 'ai-eshop-optimizer')), 'favSubProducts' => __('Products', 'ai-eshop-optimizer'), 'favSubBrands' => __('Brands', 'ai-eshop-optimizer'), 'favSubCategories'=> __('Categories', 'ai-eshop-optimizer'), 'favSubNeeds' => __('Wishes', 'ai-eshop-optimizer'), 'favSubArticles' => __('Blog posts', 'ai-eshop-optimizer'), 'favorite' => __('Favorite', 'ai-eshop-optimizer'), 'qvChoose' => __('Choose %s', 'ai-eshop-optimizer'), 'outOfStock' => __('Out of stock', 'ai-eshop-optimizer'), 'inCart' => $this->label('side_cart_in_cart_label', __('In bag', 'ai-eshop-optimizer')), 'rowQty' => __('Quantity in the bag', 'ai-eshop-optimizer'), 'qtyDown' => __('Decrease quantity', 'ai-eshop-optimizer'), 'qtyUp' => __('Increase quantity', 'ai-eshop-optimizer'), 'qtyRemove' => __('Remove from bag', 'ai-eshop-optimizer'), 'couponErr' => __('Coupon could not be applied.', 'ai-eshop-optimizer'), 'noVariationsInStock' => __('No in-stock variations available.', 'ai-eshop-optimizer'), 'pickVariation' => __('— Pick variation —', 'ai-eshop-optimizer'), 'recoSourceLabels' => array( 'sidecart_recently_viewed' => __('Recently viewed (side cart)', 'ai-eshop-optimizer'), 'sidecart_might_like' => __('You might like', 'ai-eshop-optimizer'), 'sidecart_may_also_like' => __('You may also like', 'ai-eshop-optimizer'), 'sidecart_favorites' => __('Favorites', 'ai-eshop-optimizer'), 'sidecart_quickview' => __('Quick view', 'ai-eshop-optimizer'), ), ), 'cartContents' => $this->get_cart_product_ids(), 'badgePlacements' => class_exists('AIEO_DMM_Badges') ? AIEO_DMM_Badges::get_settings()['placements'] : array( 'archive' => array('location' => 'below_favourite', 'shape' => 'circle'), 'pdp' => array('location' => 'top_left', 'shape' => 'chip'), 'recos' => array('location' => 'inline', 'shape' => 'chip'), 'side_cart' => array('location' => 'top_left', 'shape' => 'chip'), ), 'badgeSizes' => class_exists('AIEO_DMM_Badges') ? AIEO_DMM_Badges::get_settings()['sizes'] : array(), 'ga4_enabled' => ( ! class_exists('AIEO_DMM_Conversions') ) || ( 'aieo' === AIEO_DMM_Conversions::get_config()['ga_source'] && 'no' !== AIEO_DMM_Conversions::get_config()['ga_send_browser'] ), 'cardShowDesc' => class_exists('AIEO_DMM_Product_Card') ? (bool) AIEO_DMM_Product_Card::display_flag('desc_show') : false, 'cardShowRating' => class_exists('AIEO_DMM_Product_Card') ? (bool) AIEO_DMM_Product_Card::display_flag('rating_show') : true, ); if ($iapi_on) { add_action('wp_print_footer_scripts', static function () use ($side_cart_data) { echo '' . "\n"; }, 5); } else { wp_localize_script('aieo-side-cart', 'aieoSideCart', $side_cart_data); } } private function get_cart_product_ids() { if (!function_exists('WC') || !WC()->cart) { return array(); } $ids = array(); foreach (WC()->cart->get_cart() as $item) { if (!empty($item['product_id'])) { $ids[] = (int) $item['product_id']; } } return array_values(array_unique($ids)); } private function get_cart_subtotal_raw() { if (!function_exists('WC') || !WC()->cart) { return 0.0; } if (class_exists('AIEO_DMM_Pricing_Engine')) { $cart_ids = array(); foreach (WC()->cart->get_cart() as $item) { if (!empty($item['product_id'])) { $cart_ids[] = (int) $item['product_id']; } if (!empty($item['variation_id'])) { $cart_ids[] = (int) $item['variation_id']; } } $cart_ids = array_unique(array_filter($cart_ids)); if (!empty($cart_ids)) { AIEO_DMM_Pricing_Engine::instance()->preload_role_prices($cart_ids); } } $total = 0.0; foreach (WC()->cart->get_cart() as $item) { if (!empty($item['_aieo_dmm_gift_offer_id'])) { continue; } $product = isset($item['data']) ? $item['data'] : null; if (!$product || !is_a($product, 'WC_Product')) { continue; } $total += ((float) $product->get_price()) * max(0, (int) $item['quantity']); } return $total; } private function get_free_shipping_settings() { if (class_exists('AIEO_DMM_Free_Shipping')) { $engine = new AIEO_DMM_Free_Shipping(); if (method_exists($engine, 'get_settings')) { return (array) $engine->get_settings(); } } $legacy = get_option('om_fs_settings', array()); return is_array($legacy) ? $legacy : array(); } private function label($key, $default) { $plain = static function ($words) { return trim((string) preg_replace('/^[\x{2713}\x{2714}]\x{FE0F}?\s*/u', '', trim((string) $words))); }; $val = self::setting($key, ''); $val = is_string($val) ? $plain($val) : ''; return $val !== '' ? $val : $plain($default); } private function is_quick_view_context() { return !is_admin(); } private function build_action_button_css() { $rules = array(); $accent = self::colour('side_cart_accent_color'); $reco = self::colour('side_cart_reco_title_color'); $root = array(); if ($accent !== '') { $root[] = '--aieo-sc-accent:' . esc_attr($accent); $root[] = '--aieo-sc-accent-text:' . esc_attr($accent); $root[] = '--aieo-sc-badge-fg:oklch(from ' . esc_attr($accent) . ' clamp(0,(0.62 - l) * 999,1) 0 0)'; $root[] = '--aieo-sc-fs-tone:' . esc_attr($accent); $root[] = '--aieo-sc-fs-way:' . esc_attr($accent); } if ($reco !== '') { $root[] = '--aieo-sc-reco-title-color:' . esc_attr($reco); } if (!empty($root)) { $rules[] = '.aieo-sc-root{' . implode(';', $root) . ';}'; } $show_cart = self::foot_buttons()['cart']; if (!$show_cart) { $rules[] = '.aieo-sc-actions.aieo-sc-actions-checkout-only{grid-template-columns:1fr !important;}'; } $look = self::look(); foreach (array('cart', 'checkout', 'save') as $which) { $sel = '.aieo-sc-root .aieo-sc-btn-' . $which; $sel_h = $sel . ':hover,' . $sel . ':focus,' . $sel . ':visited'; $bg = self::colour('side_cart_btn_' . $which . '_bg'); $color = self::colour('side_cart_btn_' . $which . '_color'); $bstyle = (string) self::setting('side_cart_btn_' . $which . '_border_style', ''); $bcolor = self::colour('side_cart_btn_' . $which . '_border_color'); $bwidth = (int) self::setting('side_cart_btn_' . $which . '_border_width', 0); $radius = self::setting('side_cart_btn_' . $which . '_radius', null); $base_decls = array(); $hover_decls = array(); if ($bg !== '') { $base_decls[] = 'background:' . esc_attr($bg) . ' !important'; $hover_decls[] = 'background:' . esc_attr($bg) . ' !important'; } if ($color !== '') { $base_decls[] = 'color:' . esc_attr($color) . ' !important'; $hover_decls[] = 'color:' . esc_attr($color) . ' !important'; } if ($bstyle !== '' && $bstyle !== 'none') { $w = max(0, min(8, (int) $bwidth)); $c = $bcolor !== '' ? esc_attr($bcolor) : 'currentColor'; $base_decls[] = 'border:' . $w . 'px ' . esc_attr($bstyle) . ' ' . $c . ' !important'; } elseif ($bstyle === 'none' && ! $look) { $base_decls[] = 'border:0 !important'; } if ($radius !== null && $radius !== '' && ! ( $look && 24 === (int) $radius )) { $base_decls[] = 'border-radius:' . max(0, min(48, (int) $radius)) . 'px !important'; } if (!empty($base_decls)) { $rules[] = $sel . '{' . implode(';', $base_decls) . ';}'; } if (!empty($hover_decls)) { $rules[] = $sel_h . '{' . implode(';', $hover_decls) . ';}'; } } return empty($rules) ? '' : implode('', $rules); } } endif;