2 ) ); } $aieo_c_form_capture = 'aieo-card-saved-abandoned-carts-form'; $aieo_c_form_saving = 'aieo-card-saved-abandoned-carts-saved-shared-carts-form'; $aieo_c_switch_row = static function ( $name, $id, $label, $on, $help = '' ) { return \Rooster\Admin\Ui::field_row( array( 'id' => $id, 'label' => $label, 'help' => $help, 'control' => \Rooster\Admin\Ui::toggle( $name, $on, array( 'id' => $id, 'hidden' => false, 'label' => __( 'On', 'ai-eshop-optimizer' ), 'label_hidden' => true ) ), ) ); }; $aieo_c_job = ''; if ( $have_tables ) { $aieo_c_last_ts = ! empty( $lastcap['time'] ) ? (int) strtotime( $lastcap['time'] . ' UTC' ) : 0; $aieo_c_job = \Rooster\Admin\States::job( array( 'id' => 'aieo-c-job', 'state' => $aieo_c_last_ts > 0 ? 'done' : 'scheduled', 'run' => __( 'Capture abandoned carts now', 'ai-eshop-optimizer' ), 'run_attrs' => array( 'id' => 'aieo-c-capture' ), 'primary' => false, 'result' => $aieo_c_last_ts > 0 ? sprintf( __( 'Captured %1$d new, resolved %2$d.', 'ai-eshop-optimizer' ), (int) ( $lastcap['captured'] ?? 0 ), (int) ( $lastcap['resolved'] ?? 0 ) ) : '', 'last' => $aieo_c_last_ts, 'next' => __( 'Runs automatically every hour.', 'ai-eshop-optimizer' ), ) ); } list( $aieo_c_open, $aieo_c_close ) = AIEO_DMM_UI::card( array( 'anchor' => 'saved-abandoned-carts', 'icon' => 'refresh-cw', 'title' => __( 'Hourly abandonment capture', 'ai-eshop-optimizer' ), 'description' => __( 'A permanent record of every cart shoppers save/share, and every checkout cart they abandon — captured from WooCommerce block-checkout draft orders before WooCommerce purges them, with each one tracked through to converted or expired. The figures here accumulate over time and never disappear.', 'ai-eshop-optimizer' ), 'footer' => $have_tables ? \Rooster\Admin\States::save_button( $aieo_c_form_capture ) : '', 'col' => 1, ) ); echo $aieo_c_open; if ( ! $have_tables ) { echo \Rooster\Admin\States::state( 'not-set-up', array( 'title' => __( 'The cart tables are not installed yet. Open any Rooster One admin page once (or bump the plugin version) to create them, then return here.', 'ai-eshop-optimizer' ) ) ); } else { echo $aieo_c_job; ob_start(); echo '
'; echo $aieo_c_switch_row( 'capture_enabled', 'aieo-c-capture-enabled', __( 'Automatically capture abandoned carts every hour', 'ai-eshop-optimizer' ), ! empty( $set['capture_enabled'] ), __( '(turn off to stop the hourly job — the “Capture now” button above still works)', 'ai-eshop-optimizer' ) ); echo '
'; echo AIEO_DMM_UI::card_form( 'aieo_carts_save_settings', 'saved_abandoned_carts', $aieo_c_form_capture, (string) ob_get_clean() ); } echo $aieo_c_close; if ( $have_tables ) : list( $aieo_c_open, $aieo_c_close ) = AIEO_DMM_UI::card( array( 'anchor' => 'saved-abandoned-carts-abandoned-checkout-carts', 'icon' => 'calendar-x', 'title' => __( 'Abandoned checkout carts', 'ai-eshop-optimizer' ), 'description' => __( 'Drafts still being worked on stay “open”; once the shopper places the order they flip to “converted” (recovered), and if WooCommerce purges the draft without an order they become “expired” (lost). Values are the cart totals at capture (converted carts show the final order total).', 'ai-eshop-optimizer' ), 'col' => 2, ) ); echo $aieo_c_open; ?>
0 ) { echo \Rooster\Admin\Ui::stat( sprintf( __( 'In carts with a Stock-Recovery restocked product · %s carts', 'ai-eshop-optimizer' ), number_format_i18n( (int) ( $kpis['restocked_count'] ?? 0 ) ) ), $money( $kpis['restocked_value'] ?? 0 ) ); } ?>
'saved-abandoned-carts-saved-shared-carts', 'icon' => 'link', 'title' => __( 'Cart saving and sharing', 'ai-eshop-optimizer' ), 'description' => __( 'Counts the carts shoppers saved, shared and reopened, and switches on the storefront button with its label and retention days.', 'ai-eshop-optimizer' ), 'footer' => \Rooster\Admin\States::save_button( $aieo_c_form_saving ), 'col' => 1, ) ); echo $aieo_c_open; ?>
'aieo-card-saved-abandoned-carts-storefront-save-share-feature' ) ); $aieo_c_sidecart = sprintf( esc_html__( 'To show & fully style this button inside the side-cart, use %s (Action buttons → SAVE button).', 'ai-eshop-optimizer' ), '' . esc_html__( 'Side-Cart settings', 'ai-eshop-optimizer' ) . '' ); $aieo_c_howto = esc_html__( 'Shoppers get a link they can bookmark or send to someone; opening it loads the items back into the cart. You can also place the button anywhere with the shortcode', 'ai-eshop-optimizer' ) . ' [aieo_save_cart]. ' . esc_html__( 'Share links look like', 'ai-eshop-optimizer' ) . ' ' . esc_html( $share_base ) . '<token> · ' . esc_html__( '0 days = keep forever.', 'ai-eshop-optimizer' ); ob_start(); echo '
'; echo $aieo_c_switch_row( 'save_enabled', 'aieo-c-enabled', __( 'Enable the “Save / share my cart” button (cart page)', 'ai-eshop-optimizer' ), ! empty( $set['save_enabled'] ) ); echo $aieo_c_switch_row( 'show_on_checkout', 'aieo-c-checkout', __( 'Also show on the Checkout page', 'ai-eshop-optimizer' ), ! empty( $set['show_on_checkout'] ) ); $aieo_c_row = \Rooster\Admin\Ui::field_row( array( 'id' => 'aieo-c-label', 'label' => __( 'Button label', 'ai-eshop-optimizer' ), 'control' => \Rooster\Admin\Ui::input( 'save_label', (string) ( $set['save_label'] ?? '' ), array( 'id' => 'aieo-c-label', 'medium' => true, 'placeholder' => __( 'Save / share my cart', 'ai-eshop-optimizer' ) ) ), ) ); echo $aieo_c_row; $aieo_c_row = \Rooster\Admin\Ui::field_row( array( 'id' => 'aieo-c-ttl', 'label' => __( 'Keep saved carts for (days)', 'ai-eshop-optimizer' ), 'control' => \Rooster\Admin\Ui::input( 'ttl_days', (string) (int) ( $set['ttl_days'] ?? 60 ), array( 'id' => 'aieo-c-ttl', 'type' => 'number', 'min' => 0, 'max' => 3650, 'xs' => true ) ), ) ); echo $aieo_c_row; echo '
'; echo AIEO_DMM_UI::card_form( 'aieo_carts_save_settings', 'saved_abandoned_carts', $aieo_c_form_saving, (string) ob_get_clean() ); echo \Rooster\Admin\Guidance::text( '', 'guidance', array( 'html' => $aieo_c_sidecart, 'question' => __( 'How to show it in the side cart?', 'ai-eshop-optimizer' ) ) ); echo \Rooster\Admin\Guidance::text( '', 'guidance', array( 'html' => $aieo_c_howto, 'question' => __( 'How does sharing work?', 'ai-eshop-optimizer' ) ) ); echo $aieo_c_close; endif; if ( $aieo_c_band ) { rooster_admin_band_close(); } if ( $have_tables ) : $aieo_c_top_rows = array(); $aieo_c_rank = 0; foreach ( $top as $t ) { $aieo_c_rank++; $aieo_c_top_rows[] = array( 'rank' => $aieo_c_rank, 'name' => '' !== $t['name'] ? $t['name'] : ( '#' . (int) $t['product_id'] ), 'edit_url' => (int) $t['product_id'] > 0 ? admin_url( 'post.php?post=' . (int) $t['product_id'] . '&action=edit' ) : '', 'sku' => (string) ( $t['sku'] ?? '' ), 'restocked' => 1 === (int) $t['is_restocked'], 'carts' => (int) $t['carts'], 'units' => (int) $t['units'], 'sold_units' => (int) ( $t['sold_units'] ?? 0 ), 'lost_value' => (float) $t['lost_value'], 'success' => isset( $t['success_rate'] ) ? (float) $t['success_rate'] : 0.0, 'success_tip' => sprintf( __( '%1$d converted of %2$d checkout carts', 'ai-eshop-optimizer' ), (int) ( $t['sold_transactions'] ?? 0 ), (int) ( $t['checkout_carts'] ?? 0 ) ), ); } AIEO_Table::card( array( 'anchor' => 'saved-abandoned-carts-most-abandoned-products-lost-demand', 'icon' => 'package', 'heading' => 'h2', 'title' => __( 'Lost demand by product', 'ai-eshop-optimizer' ), 'description' => __( 'Ranks the products left in abandoned checkout carts by the value lost, next to the units that still sold and their success rate.', 'ai-eshop-optimizer' ), 'id' => 'aieo-c-lost-demand', 'page_id' => 'saved_abandoned_carts', 'caps' => array( 'search' => true ), 'rows' => $aieo_c_top_rows, 'empty' => __( 'No abandoned-cart items captured yet.', 'ai-eshop-optimizer' ), 'columns' => array( array( 'key' => 'rank', 'label' => '#', 'type' => 'integer', 'width' => '30px' ), array( 'key' => 'name', 'label' => __( 'Product / SKU', 'ai-eshop-optimizer' ), 'type' => 'link', 'format' => array( 'href' => 'edit_url', 'external' => true ), 'subline' => 'sku', 'suffix' => static function ( $r ) { return ! empty( $r['restocked'] ) ? __( 'restocked', 'ai-eshop-optimizer' ) : ''; }, ), array( 'key' => 'carts', 'label' => __( 'In carts', 'ai-eshop-optimizer' ), 'type' => 'integer' ), array( 'key' => 'units', 'label' => __( 'Units', 'ai-eshop-optimizer' ), 'type' => 'integer' ), array( 'key' => 'sold_units', 'label' => __( 'Sold', 'ai-eshop-optimizer' ), 'type' => 'integer', 'header_tip' => __( 'Units actually sold via converted checkout carts, since the first captured record', 'ai-eshop-optimizer' ), ), array( 'key' => 'lost_value', 'label' => __( 'Lost value', 'ai-eshop-optimizer' ), 'type' => 'money' ), array( 'key' => 'success', 'label' => __( 'Success', 'ai-eshop-optimizer' ), 'type' => 'percent', 'format' => array( 'precision' => 1 ), 'tooltip' => 'success_tip', 'header_tip' => __( 'Converted checkout carts ÷ all checkout carts the product appeared in', 'ai-eshop-optimizer' ), ), ), ) ); $aieo_c_recent_rows = array(); foreach ( $recent as $r ) { $aieo_c_oid = (int) ( $r['converted_order_id'] ? $r['converted_order_id'] : $r['wc_order_id'] ); if ( 'saved' === $r['kind'] ) { $aieo_c_outcome = 'saved'; $aieo_c_tone = 'info'; } else { $aieo_c_outcome = (string) ( $r['outcome'] ? $r['outcome'] : $r['status'] ); $aieo_c_tone = array( 'converted' => 'success', 'expired' => 'danger', 'open' => 'warning' )[ $aieo_c_outcome ] ?? 'neutral'; } $aieo_c_sub = array(); if ( 1 === (int) $r['contains_restocked'] ) { $aieo_c_sub[] = __( 'restocked', 'ai-eshop-optimizer' ); } if ( 'saved' === $r['kind'] && (int) $r['resume_count'] > 0 ) { $aieo_c_sub[] = sprintf( __( 'reopened %s×', 'ai-eshop-optimizer' ), number_format_i18n( (int) $r['resume_count'] ) ); } $aieo_c_recent_rows[] = array( 'when' => (string) $r['created_at'], 'outcome' => $aieo_c_outcome, 'outcome_tone' => $aieo_c_tone, 'outcome_sub' => implode( ' · ', $aieo_c_sub ), 'customer' => '' !== $r['customer_email'] ? $r['customer_email'] : ( (int) $r['user_id'] > 0 ? ( '#' . (int) $r['user_id'] ) : __( 'guest', 'ai-eshop-optimizer' ) ), 'items' => (int) $r['item_count'], 'total' => (float) $r['total'], 'order_no' => $aieo_c_oid > 0 ? '#' . $aieo_c_oid : '', 'order_url' => $aieo_c_oid > 0 ? admin_url( 'admin.php?page=wc-orders&action=edit&id=' . $aieo_c_oid ) : '', ); } AIEO_Table::card( array( 'anchor' => 'saved-abandoned-carts-recent-carts', 'icon' => 'clock', 'heading' => 'h2', 'title' => __( 'Recent carts', 'ai-eshop-optimizer' ), 'description' => __( 'Follow the latest saved and abandoned carts one by one: who, when, what they held and whether they became an order.', 'ai-eshop-optimizer' ), 'toolbar' => empty( $recent ) ? \Rooster\Admin\Ui::button( __( 'Export to Excel', 'ai-eshop-optimizer' ), array( 'attrs' => array( 'id' => 'aieo-c-export' ), 'reason' => __( 'Nothing to export yet.', 'ai-eshop-optimizer' ) ) ) : '' . esc_html__( 'Export to Excel', 'ai-eshop-optimizer' ) . '', 'footnote' => ! empty( $recent ) ? __( 'Showing the 100 most recent. Use “Export to Excel” for the full history.', 'ai-eshop-optimizer' ) : '', 'id' => 'aieo-c-recent', 'page_id' => 'saved_abandoned_carts', 'rows' => $aieo_c_recent_rows, 'caps' => array( 'search' => true ), 'per_page' => 0, 'filters' => array( array( 'key' => 'outcome', 'label' => __( 'Type', 'ai-eshop-optimizer' ), 'kind' => 'values', 'control' => 'segmented', 'options' => array( 'saved' => __( 'saved', 'ai-eshop-optimizer' ), 'converted' => __( 'converted', 'ai-eshop-optimizer' ), 'expired' => __( 'expired', 'ai-eshop-optimizer' ), 'open' => __( 'open', 'ai-eshop-optimizer' ), ), ), ), 'empty' => __( 'No carts recorded yet.', 'ai-eshop-optimizer' ), 'columns' => array( array( 'key' => 'when', 'label' => __( 'When', 'ai-eshop-optimizer' ), 'type' => 'datetime', 'format' => array( 'tz' => 'utc' ), 'nowrap' => true ), array( 'key' => 'outcome', 'label' => __( 'Type', 'ai-eshop-optimizer' ), 'type' => 'badge', 'format' => array( 'tone_key' => 'outcome_tone', 'labels' => array( 'saved' => __( 'saved', 'ai-eshop-optimizer' ), 'converted' => __( 'converted', 'ai-eshop-optimizer' ), 'expired' => __( 'expired', 'ai-eshop-optimizer' ), 'open' => __( 'open', 'ai-eshop-optimizer' ), ), ), 'subline' => 'outcome_sub', ), array( 'key' => 'customer', 'label' => __( 'Customer', 'ai-eshop-optimizer' ), 'type' => 'text' ), array( 'key' => 'items', 'label' => __( 'Items', 'ai-eshop-optimizer' ), 'type' => 'integer' ), array( 'key' => 'total', 'label' => __( 'Value', 'ai-eshop-optimizer' ), 'type' => 'money' ), array( 'key' => 'order_no', 'label' => __( 'Order', 'ai-eshop-optimizer' ), 'type' => 'link', 'format' => array( 'href' => 'order_url', 'external' => true ) ), ), ) ); endif; ?>