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' ) );
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() {
return 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),
);
}
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_icons_shown() ) {
foreach ( $resolved as $k => $row ) {
if ( 'cart' === $row['slug'] ) { $resolved[ $k ]['enabled'] = false; }
}
}
return $resolved;
}
private static function cart_icons_shown() {
return is_admin() || (bool) apply_filters( 'rooster/show_cart_icons', true );
}
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 function_exists( 'is_checkout' ) && is_checkout()
&& ! ( function_exists( 'is_wc_endpoint_url' ) && is_wc_endpoint_url( 'order-received' ) );
}
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 function resolve_mobile_bar_style() {
$custom = (bool) self::setting('side_cart_mbar_custom', false);
$height = max(40, min(96, (int) self::setting('side_cart_mbar_height', 58)));
$bg_set = (string) self::setting('side_cart_mbar_bg', '');
$icon_set = (string) self::setting('side_cart_mbar_icon', '');
$iconact_set = (string) self::setting('side_cart_mbar_icon_active', '');
$bbg_set = (string) self::setting('side_cart_mbar_badge_bg', '');
$bfg_set = (string) self::setting('side_cart_mbar_badge_fg', '');
$bubble_on = (bool) self::setting('side_cart_mbar_cart_bubble', true);
$hex = function ($v) { return ($v !== '' && sanitize_hex_color($v)) ? $v : ''; };
$bg = ($custom && $hex($bg_set)) ? $bg_set : 'var(--wp--preset--color--accent, #F46767)';
$ico = ($custom && $hex($icon_set)) ? $icon_set : 'var(--wp--preset--color--on-accent, var(--wp--preset--color--bg, #ffffff))';
$ico_active = $custom ? ($hex($iconact_set) ?: '#F46767') : '';
$bbg = ($custom && $hex($bbg_set)) ? $bbg_set : 'var(--wp--preset--color--fg, #1f2937)';
$bfg = ($custom && $hex($bfg_set)) ? $bfg_set : 'var(--wp--preset--color--bg, #ffffff)';
$glass = (bool) self::setting('side_cart_mbar_glass', false);
$opacity = max(0, min(100, (int) self::setting('side_cart_mbar_opacity', 70)));
$blur = max(0, min(40, (int) self::setting('side_cart_mbar_blur', 12)));
$bg_out = $glass ? sprintf('color-mix(in srgb, %s %d%%, transparent)', $bg, $opacity) : $bg;
$backdrop = $glass ? sprintf('blur(%dpx)', $blur) : 'none';
$c11 = self::theme_c11();
if ( $c11 && ! $custom ) {
$bg = 'var(--wp--preset--color--contrast, #1f2937)';
$ico = 'var(--wp--preset--color--bg, #ffffff)';
$bbg = 'var(--wp--preset--color--accent, #F46767)';
$bfg = 'var(--wp--preset--color--on-accent, var(--wp--preset--color--bg, #ffffff))';
$bg_out = $glass ? sprintf('color-mix(in srgb, %s %d%%, transparent)', $bg, $opacity) : $bg;
}
if ( ( function_exists( 'rooster_setting' ) || function_exists( 'roosterx_setting' ) ) && in_array( 'bar', (array) ( function_exists( 'rooster_setting' ) ? 'rooster_setting' : 'roosterx_setting' )( 'general', 'glass', array() ), true ) ) {
$bg_out = sprintf( 'color-mix(in srgb, %s var(--rooster-glass-mix, 70%%), transparent)', $bg );
$backdrop = 'var(--rooster-glass-filter, none)';
}
$sel_on = (bool) self::setting('side_cart_mbar_sel_enable', false);
$sel = array();
foreach (array('nav', 'search', 'chat', 'consent', 'cart') as $slug) {
$sel[$slug] = array(
'bg' => $hex((string) self::setting("side_cart_mbar_{$slug}_sel_bg", '')) ?: '#ffffff',
'fg' => $hex((string) self::setting("side_cart_mbar_{$slug}_sel_fg", '')) ?: '#1f2937',
'bc' => $hex((string) self::setting("side_cart_mbar_{$slug}_sel_bc", '')) ?: '#ffffff',
);
}
$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);
$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',
);
}
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}}';
}
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();
$fs = $this->get_free_shipping_settings();
$thresh = (float) ($fs['free_shipping_threshold'] ?? 0);
$raw = $this->get_cart_subtotal_raw();
$remaining = max(0, $thresh - $raw);
$nonce = wp_create_nonce('aieo_side_cart');
$border_enabled = (bool) self::setting('side_cart_card_border_enabled', true);
$theme_colours = '' !== self::palette_class( 'text' );
$border_color = (string) self::setting('side_cart_card_border_color', '');
$border_hover = (string) self::setting('side_cart_card_border_hover', '');
if ( $theme_colours && 0 === strcasecmp( $border_color, '#c0a37b' ) ) { $border_color = ''; }
if ( $theme_colours && 0 === strcasecmp( $border_hover, '#a88a63' ) ) { $border_hover = ''; }
if ( '' === $border_color ) { $border_color = $theme_colours ? 'var(--wp--preset--color--line)' : '#c0a37b'; }
if ( '' === $border_hover ) { $border_hover = $theme_colours ? 'var(--wp--preset--color--fg)' : '#a88a63'; }
$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();
$progress_class = 'above' === (string) self::setting('side_cart_progress_text', 'on_bar') ? '' : ' aieo-sc-pt-glass';
$reco_off = function_exists( 'rooster_design_authority' ) && 'theme' === rooster_design_authority();
if ( $reco_off ) {
$progress_class .= ' is-reco-off';
}
?>
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': ?>
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) {
$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'),
'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),
'favEnabledTypes' => class_exists('AIEO_Wishlist') ? AIEO_Wishlist::enabled_types_list() : null,
'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')),
'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' => 'inline', '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) {
$val = self::setting($key, '');
$val = is_string($val) ? trim($val) : '';
return $val !== '' ? $val : (string) $default;
}
private function is_quick_view_context() {
return !is_admin();
}
private function build_action_button_css() {
$rules = array();
$accent = (string) self::setting('side_cart_accent_color', '');
$reco = (string) self::setting('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:#ffffff';
$root[] = '--aieo-sc-fs-tone:' . 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 = (bool) self::setting('side_cart_show_cart_btn', true);
if (!$show_cart) {
$rules[] = '.aieo-sc-actions.aieo-sc-actions-checkout-only{grid-template-columns:1fr !important;}';
}
foreach (array('cart', 'checkout', 'save') as $which) {
$sel = '.aieo-sc-root .aieo-sc-btn-' . $which;
$sel_h = $sel . ':hover,' . $sel . ':focus,' . $sel . ':visited';
$bg = (string) self::setting('side_cart_btn_' . $which . '_bg', '');
$color = (string) self::setting('side_cart_btn_' . $which . '_color', '');
$bstyle = (string) self::setting('side_cart_btn_' . $which . '_border_style', '');
$bcolor = (string) self::setting('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') {
$base_decls[] = 'border:0 !important';
}
if ($radius !== null && $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;