// current sales, balance and orders add_shortcode('update_total_iconboxes', 'update_total_iconboxes_shortcode'); function update_total_iconboxes_shortcode() { // Check if WooCommerce is active if (!class_exists('WooCommerce')) { return '

WooCommerce is not active.

'; } // Check if the user is logged in if (!is_user_logged_in()) { // redirection to the Login page return ' '; } // Output HTML and JavaScript ob_start(); ?>
Wallet Balance
Loading...
Top-Up
Total Sales
Loading...
Total Orders
Loading...
'Invalid month or year')); } $month = intval($_GET['month']); $year = intval($_GET['year']); $current_user = wp_get_current_user(); if (!$current_user->ID) { wp_send_json_error(array('message' => 'User not logged in')); } $args = array( 'customer' => $current_user->ID, 'limit' => -1, 'return' => 'ids', 'date_created' => $year . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-01...' . $year . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-31', 'status' => array('completed', 'processing'), ); $customer_orders = wc_get_orders($args); $total_sales = 0; $total_orders = 0; foreach ($customer_orders as $order_id) { $order = wc_get_order($order_id); foreach ($order->get_items() as $item) { $product = $item->get_product(); if ($product && !$product->is_virtual()) { $total_sales += $item->get_total(); } } if ($total_sales > 0) { $total_orders++; } } $wallet_balance = 0; if (function_exists('woo_wallet')) { $wallet_balance = woo_wallet()->wallet->get_wallet_balance($current_user->ID, 'edit'); } wp_send_json_success(array( 'total_sales' => number_format($total_sales, 2), 'total_orders' => $total_orders, 'current_balance' => number_format($wallet_balance, 2), )); } // Greetings function custom_greeting_shortcode() { if (is_user_logged_in()) { $current_user = wp_get_current_user(); // Retrieve saved first and last names if form not submitted $first_name = get_user_meta( $current_user->ID, 'first_name', true ); $last_name = get_user_meta( $current_user->ID, 'last_name', true ); $full_name = $first_name . ' ' . $last_name; // Retrieves user first name and last name // Get current hour to determine greeting $hour = date('H'); if ($hour >= 4 && $hour < 12) { $greeting = "Good morning"; } elseif ($hour >= 12 && $hour < 16) { $greeting = "Good afternoon"; } elseif ($hour >= 16 && $hour < 22) { $greeting = "Good evening"; } else { $greeting = "Good night"; } // Return the greeting message in an h4 tag with custom background and white text color return '

' . $greeting . ', ' . esc_html($full_name) . ' 😊

'; } else { return '

Hello, Guest! 😊

'; } } add_shortcode('greeting_message', 'custom_greeting_shortcode'); // weekly chart
Scroll to Top