kingtommy dot com

MeetCritique subscription testing in production

Client project · Excerpts from the live MeetCritique code

Subscription checkout has to be tested with real card flows. This filter puts selected accounts in Stripe test mode while the live store keeps taking real payments.

wcpay_test_mode is the WooPayments filter that switches a payment between live and test. This one returns true only for a short list of user IDs, so a QA account can buy a membership with Stripe test cards on the live site and nobody else is affected.

Two limits are documented in the code. A listed account cannot make real purchases. Automatic renewals run through Action Scheduler with no logged-in user, so they are not covered, and renewals are triggered by hand from the subscription screen while an account is listed.

The filter functions.php:3880, 3882-3890
$GLOBALS['mc_wcpay_test_mode_user_ids'] = array( 3 );
// …
add_filter( 'wcpay_test_mode', 'mc_wcpay_test_mode_for_qa_users' );
function mc_wcpay_test_mode_for_qa_users( $test_mode ) {
    if ( $test_mode ) return $test_mode; // store-wide test mode already on
    if ( ! function_exists( 'is_user_logged_in' ) || ! is_user_logged_in() ) return $test_mode;
    if ( in_array( get_current_user_id(), (array) $GLOBALS['mc_wcpay_test_mode_user_ids'], true ) ) {
        return true;
    }
    return $test_mode;
}

All demos