��<?php /** * Customer Dashboard Shortcode Handler */ if ( ! defined( 'ABSPATH' ) ) exit; function curbwizard_render_customer_dashboard() { if ( ! is_user_logged_in() ) { return '<p>Please <a href="' . wp_login_url() . '">log in</a> to view your dashboard.</p>'; } $user = wp_get_current_user(); $active = sanitize_text_field( $_GET['cw_tab'] ?? 'bookings' ); $tabs = [ 'bookings' => 'My Bookings', 'properties' => 'My Properties', 'profile' => 'My Profile', 'billing' => 'Billing', ]; ob_start(); ?> <div class="cw-dashboard-container"> <!-- Header --> <header class="cw-dashboard-header"> <h1>Welcome back, <?php echo esc_html( $user->display_name ); ?>! <span class="cw-emoji">('</span></h1> <p>Manage your services, properties, and account settings from your dashboard.</p> </header> <!-- Nav --> <nav class="cw-dashboard-nav"> <?php foreach ( $tabs as $key => $label ): $cls = ( $key === $active ) ? 'cw-tab cw-tab-active' : 'cw-tab'; $url = add_query_arg( 'cw_tab', $key ); ?> <a href="<?php echo esc_url( $url ); ?>" class="<?php echo $cls; ?>"> <?php echo esc_html( $label ); ?> </a> <?php endforeach; ?> </nav> <!-- Content --> <section class="cw-dashboard-content"> <?php switch ( $active ) { case 'properties': curbwizard_render_my_properties(); break; case 'profile': curbwizard_render_my_profile(); break; case 'billing': curbwizard_render_my_billing(); break; case 'bookings': default: curbwizard_render_my_bookings(); break; } ?> </section> </div> <?php return ob_get_clean(); } add_shortcode( 'curb_customer_dashboard', 'curbwizard_render_customer_dashboard' ); /** 1) My Bookings */ function curbwizard_render_my_bookings() { $uid = get_current_user_id(); $args = [ 'post_type' => 'cw_booking', 'author' => $uid, 'post_status' => 'publish', 'numberposts' => -1, ]; $bookings = get_posts( $args ); if ( ! $bookings ) { echo '<p>No bookings found.</p>'; return; } echo '<table class="cw-table"><thead><tr> <th>Date</th><th>Services</th><th>Staff</th><th>Status</th><th>Amount</th> </tr></thead><tbody>'; foreach ( $bookings as $b ) { $date = get_post_meta( $b->ID, '_cw_booking_date', true ); $svc = get_post_meta( $b->ID, '_cw_services', true ); $staff = get_post_meta( $b->ID, '_cw_staff_id', true ); $status = get_post_meta( $b->ID, '_cw_status', true ); $amt = get_post_meta( $b->ID, '_cw_amount', true ); $staff_name = $staff ? get_the_author_meta( 'display_name', $staff ) : ' '; echo '<tr>'. '<td>'. esc_html( date( 'Y-m-d', strtotime( $date ) ) ) .'</td>'. '<td>'. esc_html( implode( ', ', (array)$svc ) ) .'</td>'. '<td>'. esc_html( $staff_name ) .'</td>'. '<td>'. esc_html( ucfirst( $status ) ) .'</td>'. '<td>$'. esc_html( number_format( $amt,2 ) ) .'</td>'. '</tr>'; } echo '</tbody></table>'; } /** 2) My Properties */ function curbwizard_render_my_properties() { $uid = get_current_user_id(); $args = [ 'post_type' => 'cw_property', 'author' => $uid, 'post_status' => 'publish', 'numberposts' => -1, ]; $props = get_posts( $args ); if ( ! $props ) { echo '<p>No properties added yet. <a href="#">Add one</a>.</p>'; return; } foreach ( $props as $p ) { $addr = get_post_meta( $p->ID, '_cw_address', true ); $gate = get_post_meta( $p->ID, '_cw_gate_code', true ); $notes = get_post_meta( $p->ID, '_cw_access_notes', true ); echo '<div class="cw-card">'; echo '<h3>'. esc_html( $p->post_title ) .'</h3>'; echo '<p>'. esc_html( $addr ) .'</p>'; if ( $gate ) { echo '<p><strong>Gate Code:</strong> '. esc_html( $gate ) .'</p>'; } if ( $notes ) { echo '<p><strong>Access Notes:</strong> '. esc_html( $notes ) .'</p>'; } echo '<p><a href="#">Book Service</a> | <a href="#">Edit Property</a></p>'; echo '</div>'; } } /** 3) My Profile */ function curbwizard_render_my_profile() { $user = wp_get_current_user(); if ( $_POST['cw_profile_update'] ?? false ) { check_admin_referer( 'cw_profile_nonce' ); $data = [ 'ID' => $user->ID, 'display_name' => sanitize_text_field( $_POST['display_name'] ), 'user_email' => sanitize_email( $_POST['user_email'] ), ]; wp_update_user( $data ); echo '<div class="cw-notice-success">Profile updated.</div>'; $user = wp_get_current_user(); } ?> <form method="post"> <?php wp_nonce_field( 'cw_profile_nonce' ); ?> <p><label>Name<br> <input type="text" name="display_name" value="<?php echo esc_attr( $user->display_name ); ?>"> </label></p> <p><label>Email<br> <input type="email" name="user_email" value="<?php echo esc_attr( $user->user_email ); ?>"> </label></p> <p><button type="submit" name="cw_profile_update">Update Profile</button></p> </form> <?php } /** 4) My Billing */ function curbwizard_render_my_billing() { ?> <h2>Current Plan</h2> <p>You have no active subscriptions.</p> <p><a class="button" href="<?php echo esc_url( add_query_arg('cw_tab','bookings') ); ?>">Book a Service</a></p> <h2>Payment Methods</h2> <p>Manage your payment details securely via Stripe.</p> <p><a class="button" href="#">Manage in Stripe Portal</a></p> <h2>Billing History</h2> <p>Your past invoices will appear here.</p> <h2>Invoices</h2> <p>Download your invoices for your records.</p> <?php } Site is undergoing maintenance
logo

Maintenance mode is on

  • Site will be available soon. Thank you for your patience!
Lost Password