bel>';
}
private function getSubscriptionPresenceCheckField() {
$field = $this->wcHelper->woocommerceFormField(
self::CHECKOUT_OPTIN_PRESENCE_CHECK_INPUT_NAME,
[
'type' => 'hidden',
'return' => true,
],
1
);
if ($field) {
return $field;
}
// Workaround for older WooCommerce versions (below 4.6.0) that don't support hidden fields
// We can remove it after we drop support of older WooCommerce
$field = $this->wcHelper->woocommerceFormField(
self::CHECKOUT_OPTIN_PRESENCE_CHECK_INPUT_NAME,
[
'type' => 'text',
'return' => true,
],
1
);
return str_replace('type="text"', 'type="hidden"', $field);
}
public function subscribeOnOrderPay($orderId) {
$wcOrder = $this->wcHelper->wcGetOrder($orderId);
if (!$wcOrder instanceof \WC_Order) {
return null;
}
$data['billing_email'] = $wcOrder->get_billing_email();
$this->subscribeOnCheckout($orderId, $data);
}
public function subscribeOnCheckout($orderId, $data) {
$this->triggerAutomateWooOptin();
if (empty($data['billing_email'])) {
// no email in posted order data
return null;
}
$subscriber = $this->subscribersRepository->findOneBy(
['email' => $data['billing_email'], 'isWoocommerceUser' => 1]
);
if (!$subscriber) {
// no subscriber: WooCommerce sync didn't work
return null;
}
$checkoutOptin = !empty($_POST[self::CHECKOUT_OPTIN_INPUT_NAME]);
return $this->handleSubscriberOptin($subscriber, $checkoutOptin);
}
/**
* Subscribe a subscriber.
*
* @param SubscriberEntity $subscriber Subscriber object
* @param bool $shouldSubscribe Whether the subscriber should be subscribed
*/
public function handleSubscriberOptin(SubscriberEntity $subscriber, bool $shouldSubscribe): bool {
$wcSegment = $this->segmentsRepository->getWooCommerceSegment();
$segmentIds = (array)$this->settings->get(self::OPTIN_SEGMENTS_SETTING_NAME, []);
$moreSegmentsToSubscribe = [];
if (!empty($segmentIds)) {
$moreSegmentsToSubscribe = $this->segmentsRepository->findBy(['id' => $segmentIds]);
}
$signupConfirmation = $this->settings->get('signup_confirmation');
if ($shouldSubscribe) {
$subscriber->setSource(Source::WOOCOMMERCE_CHECKOUT);
if (
($subscriber->getStatus() === SubscriberEntity::STATUS_SUBSCRIBED)
|| ((bool)$signupConfirmation['enabled'] === false)
) {
$this->subscribe($subscriber);
} else {
$this->requireSubscriptionConfirmation($subscriber);
}
$this->subscriberSegmentRepository->subscribeToSegments($subscriber, array_merge([$wcSegment], $moreSegmentsToSubscribe));
return true;
} else {
return false;
}
}
private function hideAutomateWooOptinCheckbox(): void {
if (!$this->wp->isPluginActive('automatewoo/automatewoo.php')) {
return;
}
// Hide AutomateWoo checkout opt-in so we won't end up with two opt-ins
$this->wp->removeAction(
'woocommerce_checkout_after_terms_and_conditions',
['AutomateWoo\Frontend', 'output_checkout_optin_checkbox']
);
}
private function triggerAutomateWooOptin(): void {
if (
!$this->wp->isPluginActive('automatewoo/automatewoo.php')
|| empty($_POST[self::CHECKOUT_OPTIN_INPUT_NAME])
) {
return;
}
// Emulate checkout opt-in triggering for AutomateWoo
$_POST['automatewoo_optin'] = 'On';
}
private function subscribe(SubscriberEntity $subscriber) {
$subscriber->setStatus(SubscriberEntity::STATUS_SUBSCRIBED);
if (empty($subscriber->getConfirmedIp()) && empty($subscriber->getConfirmedAt())) {
$subscriber->setConfirmedIp(Helpers::getIP());
$subscriber->setConfirmedAt(new Carbon());
}
$this->subscribersRepository->persist($subscriber);
$this->subscribersRepository->flush();
}
private function requireSubscriptionConfirmation(SubscriberEntity $subscriber) {
$subscriber->setStatus(SubscriberEntity::STATUS_UNCONFIRMED);
$this->subscribersRepository->persist($subscriber);
$this->subscribersRepository->flush();
try {
$this->confirmationEmailMailer->sendConfirmationEmailOnce($subscriber);
} catch (\Exception $e) {
// ignore errors
}
}
}
Fatal error: Uncaught Error: Class "MailPoet\WooCommerce\Subscription" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:5702
Stack trace:
#0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2622): MailPoetGenerated\FreeCachedContainer->getSubscription2Service()
#1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2612): MailPoetGenerated\FreeCachedContainer->getHooksWooCommerceService()
#2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getHooks2Service()
#3 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService()
#4 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1)
#5 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...')
#6 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...')
#7 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...')
#8 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...')
#9 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...')
#10 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...')
#11 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...')
#12 /htdocs/index.php(17): require('/htdocs/wp-blog...')
#13 {main}
thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 5702