g state/county', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_shipping_state(); } ), new Field( 'woocommerce:order:shipping-country', Field::TYPE_ENUM, __('Shipping country', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_shipping_country(); }, [ 'options' => $this->getShippingCountryOptions(), ] ), new Field( 'woocommerce:order:created-date', Field::TYPE_DATETIME, __('Created date', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_date_created(); } ), new Field( 'woocommerce:order:paid-date', Field::TYPE_DATETIME, __('Paid date', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_date_paid(); } ), new Field( 'woocommerce:order:customer-note', Field::TYPE_STRING, __('Customer provided note', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_customer_note(); } ), new Field( 'woocommerce:order:payment-method', Field::TYPE_ENUM, __('Payment method', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_payment_method(); }, [ 'options' => $this->getOrderPaymentOptions(), ] ), new Field( 'woocommerce:order:status', Field::TYPE_ENUM, __('Status', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_status(); }, [ 'options' => $this->getOrderStatusOptions(), ] ), new Field( 'woocommerce:order:total', Field::TYPE_NUMBER, __('Total', 'mailpoet'), function (OrderPayload $payload) { return (float)$payload->getOrder()->get_total(); } ), new Field( 'woocommerce:order:coupons', Field::TYPE_ENUM_ARRAY, __('Used coupons', 'mailpoet'), function (OrderPayload $payload) { return $payload->getOrder()->get_coupon_codes(); }, [ 'options' => $this->getCouponOptions(), ] ), new Field( 'woocommerce:order:is-first-order', Field::TYPE_BOOLEAN, __('Is first order', 'mailpoet'), function (OrderPayload $payload) { $order = $payload->getOrder(); return !$this->previousOrderExists($order); } ), new Field( 'woocommerce:order:categories', Field::TYPE_ENUM_ARRAY, __('Categories', 'mailpoet'), function (OrderPayload $payload) { $products = $this->getProducts($payload->getOrder()); $categoryIds = []; foreach ($products as $product) { $categoryIds = array_merge($categoryIds, $product->get_category_ids()); } $categoryIds = array_merge($categoryIds, $this->termParentsLoader->getParentIds($categoryIds)); sort($categoryIds); return array_unique($categoryIds); }, [ 'options' => $this->termOptionsBuilder->getTermOptions('product_cat'), ] ), new Field( 'woocommerce:order:tags', Field::TYPE_ENUM_ARRAY, __('Tags', 'mailpoet'), function (OrderPayload $payload) { $products = $this->getProducts($payload->getOrder()); $tagIds = []; foreach ($products as $product) { $tagIds = array_merge($tagIds, $product->get_tag_ids()); } sort($tagIds); return array_unique($tagIds); }, [ 'options' => $this->termOptionsBuilder->getTermOptions('product_tag'), ] ), new Field( 'woocommerce:order:products', Field::TYPE_ENUM_ARRAY, __('Products', 'mailpoet'), function (OrderPayload $payload) { $products = $this->getProducts($payload->getOrder()); return array_map(function (WC_Product $product) { return $product->get_id(); }, $products); }, [ 'options' => $this->getProductOptions(), ] ), ] ); } private function getBillingCountryOptions(): array { $options = []; foreach (WC()->countries->get_allowed_countries() as $code => $name) { $options[] = ['id' => $code, 'name' => $name]; } return $options; } private function getShippingCountryOptions(): array { $options = []; foreach (WC()->countries->get_shipping_countries() as $code => $name) { $options[] = ['id' => $code, 'name' => $name]; } return $options; } private function getOrderPaymentOptions(): array { $gateways = WC()->payment_gateways()->get_available_payment_gateways(); $options = []; foreach ($gateways as $gateway) { if ($gateway instanceof WC_Payment_Gateway && $gateway->enabled === 'yes') { $options[] = ['id' => $gateway->id, 'name' => $gateway->title]; } } return $options; } private function getOrderStatusOptions(): array { $statuses = $this->wooCommerce->wcGetOrderStatuses(); $options = []; foreach ($statuses as $id => $name) { $options[] = [ 'id' => substr($id, 0, 3) === 'wc-' ? substr($id, 3) : $id, 'name' => $name, ]; } return $options; } private function getCouponOptions(): array { $coupons = $this->wordPress->getPosts([ 'post_type' => 'shop_coupon', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'name', 'order' => 'asc', ]); $options = []; foreach ($coupons as $coupon) { if ($coupon instanceof WP_Post) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps $options[] = ['id' => $coupon->post_title, 'name' => $coupon->post_title]; } } return $options; } private function previousOrderExists(WC_Order $order): bool { $dateCreated = $order->get_date_created() ?? new DateTimeImmutable('now', $this->wordPress->wpTimezone()); $query = [ 'date_created' => '<=' . $dateCreated->getTimestamp(), 'limit' => 2, 'return' => 'ids', ]; if ($order->get_customer_id() > 0) { $query['customer_id'] = $order->get_customer_id(); } else { $query['billing_email'] = $order->get_billing_email(); } $orderIds = (array)$this->wooCommerce->wcGetOrders($query); return count($orderIds) > 1 && min($orderIds) < $order->get_id(); } /** @return WC_Product[] */ private function getProducts(WC_Order $order): array { $products = []; foreach ($order->get_items() as $item) { if (!$item instanceof WC_Order_Item_Product) { continue; } $product = $item->get_product(); if ($product instanceof WC_Product) { $products[] = $product; } } return array_unique($products); } private function getProductOptions(): array { $wpdb = $this->wordPress->getWpdb(); $products = $wpdb->get_results( " SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = 'product' AND post_status = 'publish' ORDER BY post_title ASC ", ARRAY_A ); return array_map(function ($product) { $id = $product['ID']; $title = $product['post_title']; return ['id' => (int)$id, 'name' => "$title (#$id)"]; }, (array)$products); } }
Fatal error: Uncaught Error: Class "MailPoet\Automation\Integrations\WooCommerce\Fields\OrderFieldsFactory" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:2038 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2164): MailPoetGenerated\FreeCachedContainer->getOrderFieldsFactoryService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2276): MailPoetGenerated\FreeCachedContainer->getWooCommerceIntegrationService() #2 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #3 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #4 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #5 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #6 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(206): require_once('/htdocs/wp-cont...') #7 /htdocs/wp-settings.php(462): include_once('/htdocs/wp-cont...') #8 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #9 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #10 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #11 /htdocs/index.php(17): require('/htdocs/wp-blog...') #12 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 2038