cart_item_quantity_update', [$this, 'handleCartChange'], 10 ); // item quantity set to zero (it removes the item but does not fire remove event) $this->wp->addAction( 'woocommerce_before_cart_item_quantity_zero', [$this, 'handleCartChange'], 10 ); // cart emptied (not called when all items removed) $this->wp->addAction( 'woocommerce_cart_emptied', [$this, 'handleCartChange'], 10 ); // undo removal of item from cart or cart emptying (does not fire any other cart change hook) $this->wp->addAction( 'woocommerce_cart_item_restored', [$this, 'handleCartChange'], 10 ); $this->subscriberActivityTracker->registerCallback( 'mailpoet_abandoned_cart', [$this, 'handleSubscriberActivity'] ); } public function handleCartChange() { $cart = $this->wooCommerceHelper->WC()->cart; $currentAction = current_action(); if ($currentAction !== 'woocommerce_cart_emptied' && $cart && !$cart->is_empty()) { $this->scheduleAbandonedCartEmail($this->getCartProductIds($cart)); } else { $this->cancelAbandonedCartEmail(); } } public function handleSubscriberActivity(SubscriberEntity $subscriber) { // on subscriber activity on site reschedule all currently scheduled (not yet sent) emails for given subscriber // (it tracks at most once per minute to avoid processing many calls at the same time, i.e. AJAX) $this->rescheduleAbandonedCartEmail($subscriber); } private function getCartProductIds($cart) { $cartItems = $cart->get_cart() ?: []; return array_column($cartItems, 'product_id'); } private function scheduleAbandonedCartEmail(array $cartProductIds = []) { $subscriber = $this->getSubscriber(); if (!$subscriber || $subscriber->getStatus() !== SubscriberEntity::STATUS_SUBSCRIBED) { return; } $this->wp->doAction(self::HOOK_SCHEDULE, $subscriber, $cartProductIds); $meta = [self::TASK_META_NAME => $cartProductIds]; $this->scheduler->scheduleOrRescheduleAutomaticEmail(WooCommerceEmail::SLUG, self::SLUG, $subscriber, $meta); } private function rescheduleAbandonedCartEmail(SubscriberEntity $subscriber) { $this->wp->doAction(self::HOOK_RE_SCHEDULE, $subscriber); $this->scheduler->rescheduleAutomaticEmail(WooCommerceEmail::SLUG, self::SLUG, $subscriber); } private function cancelAbandonedCartEmail() { $subscriber = $this->getSubscriber(); if (!$subscriber) { return; } $this->wp->doAction(self::HOOK_CANCEL, $subscriber); $this->scheduler->cancelAutomaticEmail(WooCommerceEmail::SLUG, self::SLUG, $subscriber); } private function getSubscriber(): ?SubscriberEntity { $wpUser = $this->wp->wpGetCurrentUser(); if ($wpUser->exists()) { return $this->subscribersRepository->findOneBy(['wpUserId' => $wpUser->ID]); } // if user not logged in, try to find subscriber by cookie $subscriberId = $this->subscriberCookie->getSubscriberId(); if ($subscriberId) { return $this->subscribersRepository->findOneById($subscriberId); } return null; } }
Fatal error: Uncaught Error: Class "MailPoet\AutomaticEmails\WooCommerce\Events\AbandonedCart" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:1371 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getAbandonedCartService() #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('AbandonedCart') #5 /htdocs/wp-includes/class-wp-hook.php(324): 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(65): 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(324): 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(65): 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(560): MailPoet\AutomaticEmails\AutomaticEmails->getAutomaticEmails() #16 /htdocs/wp-content/plugins/mailpoet/lib/Config/Initializer.php(380): MailPoet\Config\Initializer->setupAutomaticEmails() #17 /htdocs/wp-includes/class-wp-hook.php(324): MailPoet\Config\Initializer->initialize('') #18 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #19 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #20 /htdocs/wp-settings.php(704): do_action('init') #21 /htdocs/wp-config.php(85): 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 1371