abandoned_cart_id = (int) $abandoned_cart_id; $this->load_cart_data($this->abandoned_cart_id); } /** * Loads the abandoned cart data from the table. * * @param int $id * @return void */ protected function load_cart_data($id) { $cart = (new AbandonedCartRepository())->get($id); if (!$cart) { return; } $this->cart = $cart; $this->cart_data = json_decode($cart['cart_data'], true); } public function get_cart_data() { return $this->cart_data; } /** * Mimic WC_Order::get_id */ public function get_id() { return 'ac_' . $this->abandoned_cart_id; } /** * Get cart currency. */ public function get_currency() { return !empty($this->cart_data['currency']) ? $this->cart_data['currency'] : get_woocommerce_currency(); } /** * Get billing first name. */ public function get_billing_first_name() { return !empty($this->cart_data['billing_first_name']) ? $this->cart_data['billing_first_name'] : ''; } /** * Get billing last name. */ public function get_billing_last_name() { return !empty($this->cart_data['billing_last_name']) ? $this->cart_data['billing_last_name'] : ''; } /** * Get full name. */ public function get_fullname() { $first = $this->get_billing_first_name(); $last = $this->get_billing_last_name(); return trim($first . ' ' . $last); } /** * Get billing phone. */ public function get_billing_phone() { $phone = !empty($this->cart_data['phone']) ? $this->cart_data['phone'] : ''; if ($phone) { return $phone; } return !empty($this->cart['phone']) ? $this->cart['phone'] : ''; } /** * Get email (user_email) */ public function get_billing_email() { $email = !empty($this->cart_data['email']) ? $this->cart_data['email'] : ''; if ($email) { return $email; } return !empty($this->cart['email']) ? $this->cart['email'] : ''; } /** * Get phone (alias for billing_phone). */ public function get_phone() { return $this->get_billing_phone(); } /** * Get order user email (alias for get_billing_email). */ public function get_user_email() { return $this->get_billing_email(); } /** * Get order billing country. */ public function get_billing_country() { return !empty($this->cart_data['billing_country']) ? $this->cart_data['billing_country'] : ''; } /** * Get billing address 1 */ public function get_billing_address_1() { return !empty($this->cart_data['billing_address_1']) ? $this->cart_data['billing_address_1'] : ''; } /** * Get billing city. */ public function get_billing_city() { return !empty($this->cart_data['billing_city']) ? $this->cart_data['billing_city'] : ''; } /** * Get cart contents (products). */ public function get_items() { if (empty($this->cart_data['items'])) { return []; } $items = []; foreach ($this->cart_data['items'] as $item) { $items[] = new AbandonedItem($item); } return $items; } /** * Get currency symbol. */ public function get_currency_symbol() { $currency = $this->get_currency(); if (function_exists('get_woocommerce_currency_symbol')) { return get_woocommerce_currency_symbol($currency); } return ''; } /** * Get user ID (if tracked in cart table) */ public function get_user_id() { return !empty($this->cart['user_id']) ? (int)$this->cart['user_id'] : 0; } public function get_order_number() { return $this->get_id(); } public function get_total() { $total = 0; foreach ($this->get_items() as $item) { $total += $item->get_total(); } return $total; } public function get_status() { return $this->cart['status'] . '-pending'; } public function get_date_created() { //return WC_DateTime object $time = 'now'; if (!empty($this->cart['date_created'])) { $time = $this->cart['date_created']; } return new \WC_DateTime($time, new \DateTimeZone('UTC')); } public function get_payment_method_title() { return ''; } public function get_shipping_method() { return ''; } public function get_coupons() { return []; } public function get_edit_order_url() { return wc_get_cart_url(); } public function get_cart_recovery_url() { $token = $this->cart['token'] ?? ''; if (empty($token)) { return wc_get_cart_url(); } return add_query_arg('afromewo_recover_cart', $token, site_url()); } }