Skip to content

Commit

Permalink
feat(wc): force allowing subscription switching (#2305)
Browse files Browse the repository at this point in the history
Co-authored-by: leogermani <leogermani@automattic.com>
  • Loading branch information
adekbadek and leogermani authored Feb 27, 2023
1 parent 2be14c7 commit c13e741
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions includes/reader-revenue/class-woocommerce-connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WooCommerce_Connection {
*/
public static function init() {
\add_action( 'admin_init', [ __CLASS__, 'disable_woocommerce_setup' ] );
\add_filter( 'option_woocommerce_subscriptions_allow_switching_nyp_price', [ __CLASS__, 'force_allow_switching_subscription_amount' ] );

// WooCommerce Subscriptions.
\add_action( 'add_meta_boxes', [ __CLASS__, 'remove_subscriptions_schedule_meta_box' ], 45 );
Expand Down Expand Up @@ -1010,6 +1011,18 @@ public static function stripe_gateway_payment_request_data( $post_data, $order )
}
return $post_data;
}

/**
* Force allow switching the subscription amount unless the NEWSPACK_PREVENT_WC_SUBS_ALLOW_SWITCHING_OVERRIDE constant is set
*
* @param bool $can_switch Whether the subscription amount can be switched.
*/
public static function force_allow_switching_subscription_amount( $can_switch ) {
if ( defined( 'NEWSPACK_PREVENT_WC_SUBS_ALLOW_SWITCHING_OVERRIDE' ) && NEWSPACK_PREVENT_WC_SUBS_ALLOW_SWITCHING_OVERRIDE ) {
return $can_switch;
}
return 'yes';
}
}

WooCommerce_Connection::init();

0 comments on commit c13e741

Please sign in to comment.