Skip to content

Commit

Permalink
fix: apply My Account template changes only when RAS is active
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Oct 20, 2022
1 parent fb89619 commit cd7b304
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class WooCommerce_My_Account {
* @codeCoverageIgnore
*/
public static function init() {
if ( ! Reader_Activation::is_enabled() ) {
return;
}

\add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_scripts' ] );
\add_filter( 'woocommerce_account_menu_items', [ __CLASS__, 'my_account_menu_items' ], 1000 );
\add_action( 'woocommerce_account_' . self::BILLING_ENDPOINT . '_endpoint', [ __CLASS__, 'render_billing_template' ] );
Expand Down Expand Up @@ -93,9 +97,10 @@ public static function my_account_menu_items( $items ) {
return $items;
}

$default_disabled_items = [ 'dashboard', 'downloads', 'members-area', 'edit-address' ];
$default_disabled_items = [ 'dashboard', 'members-area', 'edit-address' ];
$customer_id = \get_current_user_id();
if ( function_exists( 'wcs_user_has_subscription' ) && function_exists( 'wcs_get_subscriptions' ) ) {
$user_subscriptions = wcs_get_subscriptions( [ 'customer_id' => get_current_user_id() ] );
$user_subscriptions = wcs_get_subscriptions( [ 'customer_id' => $customer_id ] );
$has_non_newspack_subscriptions = false;
foreach ( $user_subscriptions as $subscription ) {
if ( ! $subscription->get_meta( WooCommerce_Connection::SUBSCRIPTION_STRIPE_ID_META_KEY ) ) {
Expand All @@ -111,7 +116,7 @@ public static function my_account_menu_items( $items ) {
}
if ( function_exists( 'wc_get_orders' ) ) {
$wc_non_newspack_orders = array_filter(
\wc_get_orders( [ 'customer' => \get_current_user_id() ] ),
\wc_get_orders( [ 'customer' => $customer_id ] ),
function ( $order ) {
return WooCommerce_Connection::CREATED_VIA_NAME !== $order->get_created_via();
}
Expand All @@ -120,6 +125,13 @@ function ( $order ) {
$default_disabled_items = array_merge( $default_disabled_items, [ 'orders', 'payment-methods' ] );
}
}
if ( function_exists( 'wc_get_customer_available_downloads' ) ) {
$wc_customer_downloads = \wc_get_customer_available_downloads( $customer_id );

if ( empty( $wc_customer_downloads ) ) {
$default_disabled_items[] = 'downloads';
}
}
$disabled_wc_menu_items = \apply_filters( 'newspack_my_account_disabled_pages', $default_disabled_items );
foreach ( $disabled_wc_menu_items as $key ) {
if ( isset( $items[ $key ] ) ) {
Expand Down

0 comments on commit cd7b304

Please sign in to comment.