diff --git a/includes/cli/class-ras-esp-sync.php b/includes/cli/class-ras-esp-sync.php
index 907c1e8ea2..9172a81110 100644
--- a/includes/cli/class-ras-esp-sync.php
+++ b/includes/cli/class-ras-esp-sync.php
@@ -259,6 +259,9 @@ private static function sync_contacts( $config ) {
* @return bool
*/
private static function user_has_active_subscriptions( $user_id ) {
+ if ( ! function_exists( 'wcs_get_users_subscriptions' ) ) {
+ return false;
+ }
$subcriptions = array_reduce(
array_keys( \wcs_get_users_subscriptions( $user_id ) ),
function( $acc, $subscription_id ) {
diff --git a/includes/plugins/class-teams-for-memberships.php b/includes/plugins/class-teams-for-memberships.php
index 6f3af9975a..a0cc66e187 100644
--- a/includes/plugins/class-teams-for-memberships.php
+++ b/includes/plugins/class-teams-for-memberships.php
@@ -9,6 +9,7 @@
defined( 'ABSPATH' ) || exit;
+use Newspack\Donations;
use Newspack\Reader_Activation\Sync;
/**
@@ -31,7 +32,7 @@ public static function init() {
* @return bool True if enabled, false otherwise.
*/
private static function is_enabled() {
- return class_exists( 'WC_Memberships_For_Teams_Loader' );
+ return Donations::is_platform_wc() && class_exists( 'WC_Memberships_For_Teams_Loader' );
}
/**
diff --git a/includes/reader-activation/sync/class-esp-sync.php b/includes/reader-activation/sync/class-esp-sync.php
index b802767e7b..c699da7256 100644
--- a/includes/reader-activation/sync/class-esp-sync.php
+++ b/includes/reader-activation/sync/class-esp-sync.php
@@ -127,8 +127,6 @@ public static function sync( $contact, $context = '' ) {
*/
$contact = \apply_filters( 'newspack_esp_sync_contact', $contact, $context );
- $contact = Sync\Metadata::normalize_contact_data( $contact );
-
$result = \Newspack_Newsletters_Contacts::upsert( $contact, $master_list_id, $context );
return \is_wp_error( $result ) ? $result : true;
diff --git a/includes/reader-activation/sync/class-metadata.php b/includes/reader-activation/sync/class-metadata.php
index 862a75b8d4..45abc262a3 100644
--- a/includes/reader-activation/sync/class-metadata.php
+++ b/includes/reader-activation/sync/class-metadata.php
@@ -7,6 +7,7 @@
namespace Newspack\Reader_Activation\Sync;
+use Newspack\Donations;
use Newspack\Reader_Activation;
use Newspack\Logger;
@@ -35,6 +36,13 @@ class Metadata {
*/
public static $keys = [];
+ /**
+ * Initializes hooks.
+ */
+ public static function init_hooks() {
+ \add_filter( 'newspack_newsletters_contact_data', [ __CLASS__, 'normalize_contact_data' ] );
+ }
+
/**
* Get the metadata keys map for Reader Activation.
*
@@ -42,12 +50,15 @@ class Metadata {
*/
public static function get_keys() {
if ( empty( self::$keys ) ) {
+ // Only get Woo fields if using Woo.
+ $fields = Donations::is_platform_wc() ? self::get_all_fields() : self::get_basic_fields();
+
/**
* Filters the list of key/value pairs for metadata fields to be synced to the connected ESP.
*
* @param array $keys The list of key/value pairs for metadata fields to be synced to the connected ESP.
*/
- self::$keys = \apply_filters( 'newspack_ras_metadata_keys', self::get_all_fields() );
+ self::$keys = \apply_filters( 'newspack_ras_metadata_keys', $fields );
}
return self::$keys;
}
@@ -446,3 +457,4 @@ public static function normalize_contact_data( $contact ) {
return apply_filters( 'newspack_esp_sync_normalize_contact', $contact );
}
}
+Metadata::init_hooks();
diff --git a/includes/reader-activation/sync/class-woocommerce.php b/includes/reader-activation/sync/class-woocommerce.php
index 19d512bace..fb1842de12 100644
--- a/includes/reader-activation/sync/class-woocommerce.php
+++ b/includes/reader-activation/sync/class-woocommerce.php
@@ -56,7 +56,7 @@ public static function should_sync_order( $order ) {
* @return \WC_Order|false Order object or false.
*/
private static function get_current_product_order_for_sync( $customer ) {
- if ( ! is_a( $customer, 'WC_Customer' ) ) {
+ if ( ! class_exists( 'WC_Customer' ) || ! is_a( $customer, 'WC_Customer' ) ) {
return false;
}
@@ -99,6 +99,9 @@ private static function get_current_product_order_for_sync( $customer ) {
* @return ?WCS_Subscription A Subscription object or null.
*/
private static function get_most_recent_cancelled_or_expired_subscription( $user_id ) {
+ if ( ! function_exists( 'wcs_get_users_subscriptions' ) ) {
+ return;
+ }
$subscriptions = array_reduce(
array_keys( \wcs_get_users_subscriptions( $user_id ) ),
function( $acc, $subscription_id ) {
@@ -376,7 +379,7 @@ private static function get_order_metadata( $order, $payment_page_url = false )
* @return array|false Contact data or false.
*/
public static function get_contact_from_customer( $customer, $payment_page_url = false ) {
- if ( ! is_a( $customer, 'WC_Customer' ) ) {
+ if ( ! class_exists( 'WC_Customer' ) || ! is_a( $customer, 'WC_Customer' ) ) {
$customer = new \WC_Customer( $customer );
}
diff --git a/includes/reader-revenue/woocommerce/class-woocommerce-connection.php b/includes/reader-revenue/woocommerce/class-woocommerce-connection.php
index 4853d6a95a..238dc60cc7 100644
--- a/includes/reader-revenue/woocommerce/class-woocommerce-connection.php
+++ b/includes/reader-revenue/woocommerce/class-woocommerce-connection.php
@@ -263,6 +263,9 @@ public static function rate_limit_payment_methods( $is_valid ) {
* @return int[] Array of active subscription IDs.
*/
public static function get_active_subscriptions_for_user( $user_id, $product_ids = [] ) {
+ if ( ! function_exists( 'wcs_get_users_subscriptions' ) ) {
+ return [];
+ }
$subcriptions = array_reduce(
array_keys( \wcs_get_users_subscriptions( $user_id ) ),
function( $acc, $subscription_id ) use ( $product_ids ) {
diff --git a/src/wizards/readerRevenue/views/donation/index.tsx b/src/wizards/readerRevenue/views/donation/index.tsx
index 4e0cc5547a..9afc21b764 100644
--- a/src/wizards/readerRevenue/views/donation/index.tsx
+++ b/src/wizards/readerRevenue/views/donation/index.tsx
@@ -20,7 +20,7 @@ import {
TextControl,
Wizard,
} from '../../../../components/src';
-import { READER_REVENUE_WIZARD_SLUG } from '../../constants';
+import { NEWSPACK, READER_REVENUE_WIZARD_SLUG } from '../../constants';
type FrequencySlug = 'once' | 'month' | 'year';
@@ -349,6 +349,8 @@ const BillingFields = () => {
const Donation = () => {
const wizardData = Wizard.useWizardData( 'reader-revenue' ) as WizardData;
const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE );
+ const { platform_data } = wizardData;
+ const usedPlatform = platform_data?.platform;
const onSaveDonationSettings = () =>
saveWizardSettings( {
slug: READER_REVENUE_WIZARD_SLUG,
@@ -407,7 +409,7 @@ const Donation = () => {
) }
- {
}
>
-
+ ) }
>
);
};