$aieo_rp_id($name), 'label' => $label, 'control' => $control); if ($group) { $field['group'] = true; } if ('' !== $help_html) { $field['help_html'] = $help_html; } elseif ('' !== $help) { $field['help'] = $help; } return \Rooster\Admin\Ui::field_row($field); }; $aieo_rp_switch = static function ($name, $on) use ($aieo_rp_id) { return \Rooster\Admin\Ui::toggle($name, $on, array('id' => $aieo_rp_id($name), 'hidden' => false, 'label' => __('On', 'ai-eshop-optimizer'), 'label_hidden' => true)); }; $aieo_rp_editor = static function ($editor_id, $name, $label, $value, $teeny = true) { ob_start(); wp_editor($value, $editor_id, array( 'textarea_name' => $name, 'textarea_rows' => 4, 'teeny' => $teeny, 'media_buttons' => false, 'quicktags' => true, )); return \Rooster\Admin\Ui::field_row(array('id' => $editor_id, 'label' => $label, 'control' => (string) ob_get_clean())); }; $aieo_rp_px = static function ($name, $label, $placeholder) use ($settings, $aieo_rp_id) { return array( 'label' => $label, 'id' => $aieo_rp_id($name), 'control' => \Rooster\Admin\Ui::input($name, (string) ($settings[$name] ?? ''), array('id' => $aieo_rp_id($name), 'type' => 'number', 'min' => '8', 'max' => '48', 'step' => '1', 'xs' => true, 'placeholder' => $placeholder)), ); }; $aieo_rp_card = static function ($anchor, $icon, $title, $description, $fields, $opts = array()) { $form_id = 'aieo-card-' . $anchor . '-form'; $card = array( 'anchor' => $anchor, 'icon' => $icon, 'title' => $title, 'footer' => \Rooster\Admin\States::save_button($form_id, array('label' => __('Save settings', 'ai-eshop-optimizer'))), ) + $opts; if ('' !== $description) { $card['description'] = $description; } list($open, $close) = AIEO_DMM_UI::card($card); echo $open; echo AIEO_DMM_UI::card_form('aieo_dmm_role_pricing_save_settings', 'role_pricing_settings', $form_id, $fields); echo $close; }; rooster_admin_band_open(array('cols' => 2, 'min' => 35)); ob_start(); ?>
$label) : ?>
' . $aieo_rp_row( 'wpdatatables_table_id', __('wpDataTables table id (optional, for the role price table)', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('wpdatatables_table_id', (string) $viewer_table_id, array('id' => $aieo_rp_id('wpdatatables_table_id'), 'type' => 'number', 'min' => '0', 'short' => true)), $wpdt_active ? '' : __('wpDataTables plugin not detected; falls back to a native table.', 'ai-eshop-optimizer') ) . ''; $aieo_rp_card('role-pricing-enabled-roles', 'users', __('Enabled roles', 'ai-eshop-optimizer'), __('Tick the user roles that get their own prices, each of which becomes a price column in the CSV you upload.', 'ai-eshop-optimizer'), $aieo_rp_fields, array('col' => 1)); $badge_pos = isset($settings['archive_badge_position']) ? (string) $settings['archive_badge_position'] : 'image_top_left'; $aieo_rp_fields = '
' . $aieo_rp_row( 'archive_badge_position', __('Archive badge layout', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::checks('archive_badge_position', array( 'image_top_left' => __('Top-left over the product image', 'ai-eshop-optimizer'), 'below_favourite' => __('Vertical column under the favourite/wishlist icon', 'ai-eshop-optimizer'), ), array($badge_pos), array( 'type' => 'radio', 'descriptions' => array( 'image_top_left' => __('the standard WooCommerce SALE flash position', 'ai-eshop-optimizer'), 'below_favourite' => __('top-right of the card, stacked downward beneath the heart', 'ai-eshop-optimizer'), ), )), '', '', true ) . '
'; $aieo_rp_card('role-pricing-archive-badge-layout', 'layout-grid', __('Archive badge layout', 'ai-eshop-optimizer'), __('Where the SALE / PRO / Free-Gift badges appear on shop archive product cards. Whichever option you pick, the badges always stack vertically in the order SALE → PRO → Free Gift so they never overlap.', 'ai-eshop-optimizer'), $aieo_rp_fields, array('col' => 2)); $aieo_rp_login_cluster = (bool) (class_exists('AIEO_DMM_Role_Pricing') ? AIEO_DMM_Role_Pricing::login_in_cluster() : false); $aieo_rp_cluster_help = sprintf( esc_html__('When ticked, the message becomes a draggable row you can position relative to Product Meta, Categories, etc. on %s. Archive pages keep showing it next to the price.', 'ai-eshop-optimizer'), '' . esc_html__('Product Display → Display Order', 'ai-eshop-optimizer') . '' ); $aieo_rp_fields = $aieo_rp_row('show_login_message', __('Show a message to guests inviting them to log in to see role prices', 'ai-eshop-optimizer'), $aieo_rp_switch('show_login_message', !empty($settings['show_login_message']))); $aieo_rp_fields .= $aieo_rp_editor('aieo_dmm_login_message_text', 'login_message_text', __('Single-product message (HTML, may use {login_url})', 'ai-eshop-optimizer'), (string) ($settings['login_message_text'] ?? '')); $aieo_rp_fields .= $aieo_rp_editor('aieo_dmm_login_message_archive', 'login_message_archive', __('Archive message (HTML, may use {login_url})', 'ai-eshop-optimizer'), (string) ($settings['login_message_archive'] ?? '')); $aieo_rp_fields .= $aieo_rp_row('login_message_css_class', __('Custom CSS class', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('login_message_css_class', (string) ($settings['login_message_css_class'] ?? ''), array('id' => $aieo_rp_id('login_message_css_class'), 'medium' => true, 'code' => true))); $aieo_rp_fields .= $aieo_rp_row('login_message_color', __('Link colour', 'ai-eshop-optimizer'), \Rooster\Admin\Fields::color('login_message_color', (string) ($settings['login_message_color'] ?? '#c82d52'), array('id' => $aieo_rp_id('login_message_color'), 'default' => '#c82d52'))); $aieo_rp_fields .= \Rooster\Admin\Ui::field_row(array( 'id' => $aieo_rp_id('font_archive'), 'label' => __('Archive / cards font size', 'ai-eshop-optimizer'), 'parts' => array( $aieo_rp_px('login_message_font_archive_desktop', __('desktop (px)', 'ai-eshop-optimizer'), '14'), $aieo_rp_px('login_message_font_archive_mobile', __('mobile (px)', 'ai-eshop-optimizer'), '12'), ), )); $aieo_rp_fields .= \Rooster\Admin\Ui::field_row(array( 'id' => $aieo_rp_id('font_single'), 'label' => __('Single product font size', 'ai-eshop-optimizer'), 'parts' => array( $aieo_rp_px('login_message_font_single_desktop', __('desktop (px)', 'ai-eshop-optimizer'), '16'), $aieo_rp_px('login_message_font_single_mobile', __('mobile (px)', 'ai-eshop-optimizer'), '14'), ), 'help' => __('Leave a font size empty to inherit the theme size. Colour applies to the link in both contexts.', 'ai-eshop-optimizer'), )); $aieo_rp_fields .= $aieo_rp_row('login_message_modal_enabled', __('On click, open a login modal (login form + social sign-in + the content below) instead of going to My Account', 'ai-eshop-optimizer'), $aieo_rp_switch('login_message_modal_enabled', !empty($settings['login_message_modal_enabled'])), __('Social sign-in shows only if you have enabled providers for the “login” intent under Social login.', 'ai-eshop-optimizer')); $aieo_rp_fields .= $aieo_rp_editor('aieo_dmm_login_message_modal_content', 'login_message_modal_content', __('Modal content (rich text — e.g. a link to your professionals page)', 'ai-eshop-optimizer'), (string) ($settings['login_message_modal_content'] ?? ''), false); $aieo_rp_fields .= $aieo_rp_row('login_message_in_cluster', __('Position the single-product message in the product info column (orderable) instead of attached to the price', 'ai-eshop-optimizer'), $aieo_rp_switch('login_message_in_cluster', $aieo_rp_login_cluster), '', $aieo_rp_cluster_help); $aieo_rp_card('role-pricing-login-message', 'message-square-text', __('Login message', 'ai-eshop-optimizer'), __('Write the message that invites guests to log in to see role prices, and choose what opens when they click it.', 'ai-eshop-optimizer'),'
' . $aieo_rp_fields . '
', array('col' => 1, 'span' => 'all')); $aieo_rp_fields = $aieo_rp_row('mini_cart_badge_icon', __('Icon', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('mini_cart_badge_icon', (string) ($settings['mini_cart_badge_icon'] ?? ''), array('id' => $aieo_rp_id('mini_cart_badge_icon'), 'xs' => true, 'placeholder' => '%')), __('Emoji, glyph or short HTML (e.g. ⓘ, %, an <img> tag). Leave empty to use just the text label.', 'ai-eshop-optimizer')); $aieo_rp_fields .= $aieo_rp_row('mini_cart_badge_text', __('Text label', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('mini_cart_badge_text', (string) ($settings['mini_cart_badge_text'] ?? ''), array('id' => $aieo_rp_id('mini_cart_badge_text'), 'short' => true, 'placeholder' => 'PRO')), __('Short word shown next to the icon (1–4 characters works best). Plain text only.', 'ai-eshop-optimizer')); $aieo_rp_fields .= $aieo_rp_row('mini_cart_badge_alt', __('Tooltip text (HTML)', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::textarea('mini_cart_badge_alt', (string) ($settings['mini_cart_badge_alt'] ?? ''), array('id' => $aieo_rp_id('mini_cart_badge_alt'), 'rows' => 3, 'placeholder' => __('Defaults to the single-product message above when empty.', 'ai-eshop-optimizer'))), __('Shown when the badge is hovered (desktop) or tapped (mobile). May use {login_url}.', 'ai-eshop-optimizer')); $aieo_rp_card('role-pricing-mini-cart-badge', 'shopping-cart', __('Mini-cart badge', 'ai-eshop-optimizer'), __('Compact form of the message above, shown next to the price on the side cart, recently viewed, and recommendation cards. Hovering / tapping the badge reveals the full message as a tooltip. Same gate as above (only shows to anonymous users on products with role pricing).', 'ai-eshop-optimizer'), '
' . $aieo_rp_fields . '
', array('col' => 1)); rooster_admin_band_close(); ?> 2, 'min' => 35)); list($aieo_rp_open, $aieo_rp_close) = AIEO_DMM_UI::card(array( 'anchor' => 'role-pricing-csv-upload', 'icon' => 'table', 'title' => __('CSV upload', 'ai-eshop-optimizer'), 'description' => __('Upload a CSV with one sku column and one column per enabled role. Prices accept both "." and "," decimal separators.', 'ai-eshop-optimizer'), 'col' => 1, )); echo $aieo_rp_open; $aieo_rp_up = $aieo_rp_row( 'mode', __('Import mode', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::checks('mode', array( 'merge' => __('Merge (update existing, add new)', 'ai-eshop-optimizer'), 'overwrite' => __('Overwrite (truncate + re-import)', 'ai-eshop-optimizer'), ), array('merge'), array('type' => 'radio')), '', '', true ); $aieo_rp_up .= \Rooster\Admin\Ui::field_row(array( 'id' => 'aieo-rp-csv-file', 'label' => __('CSV file', 'ai-eshop-optimizer'), 'required' => true, 'control' => \Rooster\Admin\Ui::file( 'csv_file', array( 'id' => 'aieo-rp-csv-file', 'accept' => '.csv,text/csv', 'required' => true ) ), )); $aieo_rp_tpl = \Rooster\Admin\Ui::button(__('Download sample template', 'ai-eshop-optimizer'), array('icon' => 'download', 'class' => 'aieo-dmm-btn-fixed aieo-dmm-download-template', 'attrs' => array('data-action' => 'aieo_dmm_role_pricing_download_template'))); $aieo_rp_exp = \Rooster\Admin\Ui::button(__('Export current prices', 'ai-eshop-optimizer'), array('icon' => 'download', 'class' => 'aieo-dmm-btn-fixed aieo-dmm-export-prices', 'attrs' => array('data-action' => 'aieo_dmm_role_pricing_export'))); ?>
' . $aieo_rp_up . ''; ?>
'aieo-dmm-role-job', 'state' => 'idle', 'run' => __('Upload & process', 'ai-eshop-optimizer'), 'run_attrs' => array('id' => 'aieo-rp-upload-btn', 'form' => 'aieo-dmm-role-upload-form', 'data-action' => 'aieo_dmm_role_pricing_upload'), 'detail' => '', )); echo $aieo_rp_job; $aieo_rp_ask = \Rooster\Admin\States::confirm( 'aieo-rp-overwrite-confirm', 'replace', __('Overwrite the role prices?', 'ai-eshop-optimizer'), '

' . esc_html(sprintf( _n('Empties the role price table (%s product row now) and imports the file in its place.', 'Empties the role price table (%s product rows now) and imports the file in its place.', (int) $total_rows, 'ai-eshop-optimizer'), number_format_i18n((int) $total_rows) )) . '

' . esc_html__('Prices that are not in the file are gone afterwards.', 'ai-eshop-optimizer') . '

', array('confirm' => __('Overwrite', 'ai-eshop-optimizer')) ); echo $aieo_rp_ask; ?> 'role-pricing-current-role-prices', 'icon' => 'list', 'title' => __('Current role prices', 'ai-eshop-optimizer') . ' (' . (int) $total_rows . ')', 'description' => __('Browse the imported prices, product by product, with one column for each enabled role.', 'ai-eshop-optimizer'), 'flush' => !($wpdt_active && $viewer_table_id > 0) && !empty($price_rows), 'col' => 2, )); echo $aieo_rp_open; ?> 0) : ?> __('No role prices imported yet.', 'ai-eshop-optimizer'))); ?> 'product_id', 'label' => __('Product ID', 'ai-eshop-optimizer'), 'type' => 'id'), array('key' => 'sku', 'label' => __('SKU', 'ai-eshop-optimizer'), 'type' => 'code'), array('key' => 'product_type', 'label' => __('Type', 'ai-eshop-optimizer')), ); $aieo_rp_keys = array(); foreach ($enabled_roles as $aieo_rp_role) { $aieo_rp_col = 'role_' . strtolower(preg_replace('/[^a-z0-9_]/', '_', $aieo_rp_role)); if (preg_match('/^role_[0-9]/', $aieo_rp_col)) { $aieo_rp_col = 'role_r_' . substr($aieo_rp_col, 5); } $aieo_rp_keys[$aieo_rp_role] = $aieo_rp_col; $aieo_rp_cols[] = array('key' => $aieo_rp_col, 'label' => $aieo_rp_role, 'type' => 'money'); } $aieo_rp_rows = array(); foreach ($price_rows as $aieo_rp_row) { $aieo_rp_out = array( 'product_id' => (int) $aieo_rp_row['product_id'], 'sku' => (string) ($aieo_rp_row['sku'] ?? ''), 'product_type' => (string) ($aieo_rp_row['product_type'] ?? ''), ); foreach ($aieo_rp_keys as $aieo_rp_col) { $aieo_rp_out[$aieo_rp_col] = isset($aieo_rp_row[$aieo_rp_col]) ? $aieo_rp_row[$aieo_rp_col] : null; } $aieo_rp_rows[] = $aieo_rp_out; } AIEO_Table::render(array( 'page_id' => 'role_pricing', 'row_key' => 'product_id', 'rows' => $aieo_rp_rows, 'columns' => $aieo_rp_cols, 'sortable' => false, 'density' => 'compact', 'cap' => (int) $per_page, 'capped' => (int) $total_rows > (int) $per_page, 'total' => (int) $total_rows, )); ?> 1) : $base_url = add_query_arg(array( 'page' => AIEO_DMM::MENU_SLUG, 'dmm_tab' => 'role_pricing', ), admin_url('admin.php')); echo '
'; echo wp_kses_post(paginate_links(array( 'base' => $base_url . '%_%', 'format' => '&paged=%#%', 'current' => (int) $current_page, 'total' => $total_pages, 'prev_text' => '«', 'next_text' => '»', ))); echo '
'; endif; ?>