$subscriber, $queue) { $result = $shortcode; if ($shortcode === self::ORDER_DATE_SHORTCODE) { $defaultValue = WPFunctions::get()->dateI18n(get_option('date_format')); if (!$queue) { $result = $defaultValue; } else { $meta = $queue->getMeta(); $result = (!empty($meta['order_date'])) ? WPFunctions::get()->dateI18n(get_option('date_format'), $meta['order_date']) : $defaultValue; } } $this->loggerFactory->getLogger(self::SLUG)->info( 'handleOrderDateShortcode called', [ 'newsletter_id' => ($newsletter instanceof NewsletterEntity) ? $newsletter->getId() : null, 'subscriber_id' => ($subscriber instanceof SubscriberEntity) ? $subscriber->getId() : null, 'task_id' => ($queue instanceof SendingQueueEntity) ? (($task = $queue->getTask()) ? $task->getId() : null) : null, 'shortcode' => $shortcode, 'result' => $result, ] ); return $result; } public function handleOrderTotalShortcode($shortcode, $newsletter, $subscriber, $queue) { $result = $shortcode; if ($shortcode === self::ORDER_TOTAL_SHORTCODE) { $defaultValue = $this->helper->wcPrice(0); if (!$queue) { $result = $defaultValue; } else { $meta = $queue->getMeta(); $result = (!empty($meta['order_amount'])) ? $this->helper->wcPrice($meta['order_amount']) : $defaultValue; } } $this->loggerFactory->getLogger(self::SLUG)->info( 'handleOrderTotalShortcode called', [ 'newsletter_id' => ($newsletter instanceof NewsletterEntity) ? $newsletter->getId() : null, 'subscriber_id' => ($subscriber instanceof SubscriberEntity) ? $subscriber->getId() : null, 'task_id' => ($queue instanceof SendingQueueEntity) ? (($task = $queue->getTask()) ? $task->getId() : null) : null, 'shortcode' => $shortcode, 'result' => $result, ] ); return $result; } public function scheduleEmailWhenOrderIsPlaced($orderId) { $orderDetails = $this->helper->wcGetOrder($orderId); if (!$orderDetails || !$orderDetails->get_billing_email()) { $this->loggerFactory->getLogger(self::SLUG)->info( 'Email not scheduled because the order customer was not found', ['order_id' => $orderId] ); return; } $customerEmail = $orderDetails->get_billing_email(); $customerOrderCount = $this->getCustomerOrderCount($customerEmail); if ($customerOrderCount > 1) { $this->loggerFactory->getLogger(self::SLUG)->info( 'Email not scheduled because this is not the first order of the customer', [ 'order_id' => $orderId, 'customer_email' => $customerEmail, 'order_count' => $customerOrderCount, ] ); return; } $meta = [ 'order_amount' => $orderDetails->get_total(), 'order_date' => $orderDetails->get_date_created()->getTimestamp(), 'order_id' => $orderDetails->get_id(), ]; $subscriber = $this->subscribersRepository->getWooCommerceSegmentSubscriber($customerEmail); if (!$subscriber instanceof SubscriberEntity) { $this->loggerFactory->getLogger(self::SLUG)->info( 'Email not scheduled because the customer was not found as WooCommerce list subscriber', ['order_id' => $orderId, 'customer_email' => $customerEmail] ); return; } $checkEmailWasNotScheduled = function (NewsletterEntity $newsletter) use ($subscriber) { return !$this->automaticEmailsRepository->wasScheduledForSubscriber((int)$newsletter->getId(), (int)$subscriber->getId()); }; $this->loggerFactory->getLogger(self::SLUG)->info( 'Email scheduled', [ 'order_id' => $orderId, 'customer_email' => $customerEmail, 'subscriber_id' => $subscriber->getId(), ] ); $this->scheduler->scheduleAutomaticEmail(WooCommerce::SLUG, self::SLUG, $checkEmailWasNotScheduled, $subscriber, $meta); } public function getCustomerOrderCount($customerEmail) { // registered user $user = WPFunctions::get()->getUserBy('email', $customerEmail); if ($user) { return $this->helper->wcGetCustomerOrderCount($user->ID); } // guest user return $this->getGuestCustomerOrderCountByEmail($customerEmail); } private function getGuestCustomerOrderCountByEmail(string $customerEmail): int { $ordersCount = $this->helper->wcGetOrders( [ 'status' => 'all', 'type' => 'shop_order', 'billing_email' => $customerEmail, 'limit' => 1, 'return' => 'ids', 'paginate' => true, ] )->total; return $ordersCount; } }
Fatal error: Uncaught Error: Class "MailPoet\AutomaticEmails\WooCommerce\Events\FirstPurchase" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:1265 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getFirstPurchaseService() #1 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Automa...', 1) #2 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Automa...') #3 /htdocs/wp-content/plugins/mailpoet/lib/AutomaticEmails/WooCommerce/WooCommerceEventFactory.php(37): MailPoet\DI\ContainerWrapper->get('MailPoet\\Automa...') #4 /htdocs/wp-content/plugins/mailpoet/lib/AutomaticEmails/WooCommerce/WooCommerce.php(82): MailPoet\AutomaticEmails\WooCommerce\WooCommerceEventFactory->createEvent('FirstPurchase') #5 /htdocs/wp-includes/class-wp-hook.php(310): MailPoet\AutomaticEmails\WooCommerce\WooCommerce->setupEvents(Array) #6 /htdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #7 [internal function]: apply_filters('mailpoet_woocom...', Array) #8 /htdocs/wp-content/plugins/mailpoet/lib/WP/Functions.php(49): call_user_func_array('apply_filters', Array) #9 /htdocs/wp-content/plugins/mailpoet/lib/AutomaticEmails/WooCommerce/WooCommerce.php(70): MailPoet\WP\Functions->applyFilters('mailpoet_woocom...', Array) #10 /htdocs/wp-includes/class-wp-hook.php(310): MailPoet\AutomaticEmails\WooCommerce\WooCommerce->setupGroup(Array) #11 /htdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #12 [internal function]: apply_filters('mailpoet_automa...', Array) #13 /htdocs/wp-content/plugins/mailpoet/lib/WP/Functions.php(49): call_user_func_array('apply_filters', Array) #14 /htdocs/wp-content/plugins/mailpoet/lib/AutomaticEmails/AutomaticEmails.php(49): MailPoet\WP\Functions->applyFilters('mailpoet_automa...', Array) #15 /htdocs/wp-content/plugins/mailpoet/lib/Config/Initializer.php(492): MailPoet\AutomaticEmails\AutomaticEmails->getAutomaticEmails() #16 /htdocs/wp-content/plugins/mailpoet/lib/Config/Initializer.php(333): MailPoet\Config\Initializer->setupAutomaticEmails() #17 /htdocs/wp-includes/class-wp-hook.php(310): MailPoet\Config\Initializer->initialize('') #18 /htdocs/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #19 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #20 /htdocs/wp-settings.php(632): do_action('init') #21 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #22 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #23 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #24 /htdocs/index.php(17): require('/htdocs/wp-blog...') #25 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 1265