admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'maple_carts_admin' ), 'confirmDelete' => __( 'Are you sure you want to delete this?', 'maple-carts' ), 'saving' => __( 'Saving...', 'maple-carts' ), 'saved' => __( 'Saved!', 'maple-carts' ), ] ); // Enqueue WP editor for email templates. if ( strpos( $hook, 'maple-carts-emails' ) !== false ) { wp_enqueue_editor(); } } /** * Handle form actions. */ public function handle_actions() { // Save settings. if ( isset( $_POST['maple_carts_save_settings'] ) && check_admin_referer( 'maple_carts_settings' ) ) { $this->save_settings(); } } /** * Save settings. */ private function save_settings() { $settings = [ 'enabled' => isset( $_POST['enabled'] ) ? 'yes' : 'no', 'cart_cutoff_time' => absint( $_POST['cart_cutoff_time'] ?? 15 ), 'delete_after_days' => absint( $_POST['delete_after_days'] ?? 90 ), 'email_mode' => isset( $_POST['email_mode'] ) && 'mailjet' === $_POST['email_mode'] ? 'mailjet' : 'builtin', 'mailjet_api_key' => sanitize_text_field( wp_unslash( $_POST['mailjet_api_key'] ?? '' ) ), 'mailjet_secret_key'=> sanitize_text_field( wp_unslash( $_POST['mailjet_secret_key'] ?? '' ) ), 'from_name' => sanitize_text_field( wp_unslash( $_POST['from_name'] ?? '' ) ), 'from_email' => sanitize_email( wp_unslash( $_POST['from_email'] ?? '' ) ), 'reply_to' => sanitize_email( wp_unslash( $_POST['reply_to'] ?? '' ) ), 'notify_admin' => isset( $_POST['notify_admin'] ) ? 'yes' : 'no', 'admin_email' => sanitize_email( wp_unslash( $_POST['admin_email'] ?? '' ) ), 'require_consent' => isset( $_POST['require_consent'] ) ? 'yes' : 'no', 'consent_text' => sanitize_text_field( wp_unslash( $_POST['consent_text'] ?? '' ) ), 'show_delete_link' => isset( $_POST['show_delete_link'] ) ? 'yes' : 'no', 'gdpr_notice' => sanitize_textarea_field( wp_unslash( $_POST['gdpr_notice'] ?? '' ) ), 'exclude_roles' => isset( $_POST['exclude_roles'] ) ? array_map( 'sanitize_text_field', $_POST['exclude_roles'] ) : [], ]; update_option( 'maple_carts_settings', $settings ); add_settings_error( 'maple_carts', 'settings_saved', __( 'Settings saved.', 'maple-carts' ), 'success' ); } /** * Render dashboard page. */ public function render_dashboard() { $period = isset( $_GET['period'] ) ? sanitize_text_field( wp_unslash( $_GET['period'] ) ) : '30days'; $stats = Maple_Carts_DB::get_stats( $period ); ?>

%
render_carts_table( 'abandoned', __( 'Abandoned Carts', 'maple-carts' ) ); } /** * Render recovered carts page. */ public function render_recovered_carts() { $this->render_carts_table( 'recovered', __( 'Recovered Carts', 'maple-carts' ) ); } /** * Render carts table. * * @param string $status Page status. * @param string $title Page title. */ private function render_carts_table( $status, $title ) { $page = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; $limit = 20; $offset = ( $page - 1 ) * $limit; $carts = Maple_Carts_DB::get_carts_by_status( $status, $limit, $offset ); $total = Maple_Carts_DB::count_carts_by_status( $status ); $pages = ceil( $total / $limit ); ?>

cart_contents ); $product_count = is_array( $cart_contents ) ? count( $cart_contents ) : 0; ?>
email ); ?> unsubscribed ) : ?> customer_name ?: '—' ); ?> cart_total, [ 'currency' => $cart->currency ] ); ?> recovered_at ? $cart->recovered_at : ( $cart->abandoned_at ?: $cart->created_at ); echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date ) ) ); ?>
1 ) : ?>
add_query_arg( 'paged', '%#%' ), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $pages, 'current' => $page, ] ); ?>

include_coupon ) ? 'style="display:none;"' : ''; ?>> include_coupon ) ? 'style="display:none;"' : ''; ?>> include_coupon ) ? 'style="display:none;"' : ''; ?>>

body : '', 'template-body', [ 'textarea_name' => 'body', 'textarea_rows' => 15, 'media_buttons' => false, ] ); ?>


{{customer_name}}, {{customer_email}}, {{cart_contents}}, {{cart_total}}, {{product_names}}, {{recovery_url}}, {{coupon_code}}, {{coupon_amount}}, {{coupon_expires}}, {{site_name}}, {{unsubscribe_link}}, {{delete_data_link}}

name ); ?> subject ); ?> delay_value . ' ' . $tmpl->delay_unit ); ?> include_coupon ) : ?> coupon_type === 'percent' ? esc_html( $tmpl->coupon_amount . '%' ) : wc_price( $tmpl->coupon_amount ); ?> |



Mailjet API Keys' ); ?>

    get_available_properties() as $prop => $desc ) : ?>

maple_has_abandoned_cart equals true

' . esc_html__( 'Privacy Settings', 'maple-carts' ) . '' ); ?>

roles as $role_key => $role ) : ?>

sanitize_text_field( wp_unslash( $_POST['name'] ?? '' ) ), 'subject' => sanitize_text_field( wp_unslash( $_POST['subject'] ?? '' ) ), 'body' => wp_kses_post( wp_unslash( $_POST['body'] ?? '' ) ), 'delay_value' => absint( $_POST['delay_value'] ?? 1 ), 'delay_unit' => $delay_unit, 'is_active' => isset( $_POST['is_active'] ) ? 1 : 0, 'include_coupon' => isset( $_POST['include_coupon'] ) ? 1 : 0, 'coupon_type' => $coupon_type, 'coupon_amount' => floatval( $_POST['coupon_amount'] ?? 10 ), 'coupon_expires_days'=> absint( $_POST['coupon_expires_days'] ?? 7 ), ]; if ( ! empty( $_POST['id'] ) ) { $data['id'] = absint( $_POST['id'] ); } $id = Maple_Carts_DB::save_email_template( $data ); if ( $id ) { wp_send_json_success( [ 'id' => $id ] ); } else { wp_send_json_error( 'Failed to save template' ); } } /** * AJAX: Delete template. */ public function ajax_delete_template() { check_ajax_referer( 'maple_carts_admin', 'nonce' ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error( 'Permission denied' ); } $id = isset( $_POST['template_id'] ) ? absint( $_POST['template_id'] ) : 0; if ( ! $id ) { wp_send_json_error( 'Invalid template ID' ); } if ( Maple_Carts_DB::delete_email_template( $id ) ) { wp_send_json_success(); } else { wp_send_json_error( 'Failed to delete template' ); } } /** * AJAX: Toggle template active status. */ public function ajax_toggle_template() { check_ajax_referer( 'maple_carts_admin', 'nonce' ); if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error( 'Permission denied' ); } $id = isset( $_POST['template_id'] ) ? absint( $_POST['template_id'] ) : 0; $active = isset( $_POST['active'] ) ? absint( $_POST['active'] ) : 0; if ( ! $id ) { wp_send_json_error( 'Invalid template ID' ); } global $wpdb; $result = $wpdb->update( $wpdb->prefix . MAPLE_CARTS_EMAILS_TABLE, [ 'is_active' => $active ? 0 : 1 ], [ 'id' => $id ] ); if ( false !== $result ) { wp_send_json_success( [ 'is_active' => $active ? 0 : 1 ] ); } else { wp_send_json_error( 'Failed to update template' ); } } }